2020-02-20 05:46:44 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-10-07 04:11:36 +00:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"go.jolheiser.com/gpm/config"
|
|
|
|
"go.jolheiser.com/gpm/router"
|
|
|
|
|
2020-02-20 05:46:44 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2020-02-20 19:09:56 +00:00
|
|
|
"go.jolheiser.com/beaver"
|
2020-02-20 05:46:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var Server = cli.Command{
|
|
|
|
Name: "server",
|
|
|
|
Usage: "Start the gpm server",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "port",
|
|
|
|
Aliases: []string{"p"},
|
|
|
|
Usage: "Port to run the gpm server on",
|
|
|
|
Value: "3333",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: doServer,
|
|
|
|
}
|
|
|
|
|
|
|
|
func doServer(ctx *cli.Context) error {
|
2020-10-07 04:11:36 +00:00
|
|
|
cfg, err := config.Load()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-20 05:46:44 +00:00
|
|
|
beaver.Infof("Running gpm server at http://localhost:%s", ctx.String("port"))
|
2020-10-07 04:11:36 +00:00
|
|
|
if err := http.ListenAndServe(fmt.Sprintf(":%s", ctx.String("port")), router.New(cfg)); err != nil {
|
2020-02-20 05:46:44 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|