demo-web-service-go/cmd/run.go

30 lines
586 B
Go
Raw Permalink Normal View History

2021-09-14 13:02:03 +03:00
package cmd
import (
"fmt"
"time"
"github.com/Neur0toxine/demo-web-service-go/internal/app"
2021-09-14 13:02:03 +03:00
"github.com/brianvoe/gofakeit/v6"
)
func init() {
_, err := Parser.AddCommand("run", "Run the application", "", &RunCommand{})
if err != nil {
panic(err)
}
}
// RunCommand is used to run the server
type RunCommand struct{}
func (c *RunCommand) Execute(args []string) error {
gofakeit.Seed(time.Now().UnixNano())
go app.ProcessSignals()
r := app.Router()
2021-09-14 13:02:03 +03:00
if err := r.Run(":8080"); err != nil {
return fmt.Errorf("cannot start the server on :8080 > %w", err)
}
return nil
}