2021-09-14 13:02:03 +03:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2021-09-14 13:04:56 +03:00
|
|
|
"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())
|
2021-09-14 13:04:56 +03:00
|
|
|
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
|
|
|
|
}
|