gpm/cmd/server.go

40 lines
733 B
Go

package cmd
import (
"fmt"
"net/http"
"go.jolheiser.com/gpm/config"
"go.jolheiser.com/gpm/router"
"github.com/urfave/cli/v2"
"go.jolheiser.com/beaver"
)
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 {
cfg, err := config.Load()
if err != nil {
return err
}
beaver.Infof("Running gpm server at http://localhost:%s", ctx.String("port"))
if err := http.ListenAndServe(fmt.Sprintf(":%s", ctx.String("port")), router.New(cfg)); err != nil {
return err
}
return nil
}