Closes #229 This is a MVP and only includes maps. Reviewed-on: #253 Reviewed-by: itzaname <itzaname@noreply@itzana.me> Co-authored-by: Rhys Lloyd <krakow20@gmail.com> Co-committed-by: Rhys Lloyd <krakow20@gmail.com>
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package cmds
|
|
|
|
import (
|
|
"git.itzana.me/strafesnet/maps-service/pkg/public_api"
|
|
"github.com/urfave/cli/v2"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
)
|
|
|
|
func NewApiCommand() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "api",
|
|
Usage: "Run api service",
|
|
Action: runAPI,
|
|
Flags: []cli.Flag{
|
|
&cli.IntFlag{
|
|
Name: "port",
|
|
Usage: "Listen port",
|
|
EnvVars: []string{"PORT"},
|
|
Value: 8080,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "dev-rpc-host",
|
|
Usage: "Host of dev rpc",
|
|
EnvVars: []string{"DEV_RPC_HOST"},
|
|
Value: "dev-service:8081",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "maps-rpc-host",
|
|
Usage: "Host of maps rpc",
|
|
EnvVars: []string{"MAPS_RPC_HOST"},
|
|
Value: "maptest-api:8081",
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func runAPI(ctx *cli.Context) error {
|
|
// Dev service client
|
|
devConn, err := grpc.Dial(ctx.String("dev-rpc-host"), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Data service client
|
|
mapsConn, err := grpc.Dial(ctx.String("maps-rpc-host"), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return api.NewRouter(
|
|
api.WithContext(ctx),
|
|
api.WithPort(ctx.Int("port")),
|
|
api.WithDevClient(devConn),
|
|
api.WithMapsClient(mapsConn),
|
|
)
|
|
}
|