altcha-server/internal/command/run.go

35 lines
798 B
Go
Raw Normal View History

2024-09-11 09:54:55 +02:00
package command
import (
"forge.cadoles.com/cadoles/altcha-server/internal/api"
"forge.cadoles.com/cadoles/altcha-server/internal/command/common"
"forge.cadoles.com/cadoles/altcha-server/internal/config"
"github.com/caarlos0/env/v11"
"github.com/urfave/cli/v2"
2024-09-13 09:12:16 +02:00
"gitlab.com/wpetit/goweb/logger"
2024-09-11 09:54:55 +02:00
)
func RunCommand() *cli.Command {
flags := common.Flags()
return &cli.Command{
Name: "run",
Usage: "run the atlcha api server",
Flags: flags,
Action: func(ctx *cli.Context) error {
cfg := config.Config{}
if err := env.Parse(&cfg); err != nil {
2024-09-13 09:12:16 +02:00
logger.Error(ctx.Context, err.Error())
return err
}
server, err := api.NewServer(cfg)
if err != nil {
logger.Error(ctx.Context, err.Error())
return err
2024-09-11 09:54:55 +02:00
}
2024-09-13 09:12:16 +02:00
server.Run(ctx.Context)
2024-09-11 09:54:55 +02:00
return nil
},
}
}