2025-05-05 17:53:00 -03:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2025-05-15 13:03:16 -03:00
|
|
|
"sirherobrine23.com.br/go-bds/bds/modules/router"
|
2025-05-05 17:53:00 -03:00
|
|
|
"sirherobrine23.com.br/go-bds/bds/modules/datas"
|
2025-05-06 00:31:10 -03:00
|
|
|
httpserver "sirherobrine23.com.br/go-bds/bds/modules/http_server"
|
2025-05-05 17:53:00 -03:00
|
|
|
|
|
|
|
"github.com/chaindead/zerocfg"
|
|
|
|
"github.com/chaindead/zerocfg/env"
|
|
|
|
"github.com/chaindead/zerocfg/yaml"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Web subcommand
|
|
|
|
var API = &cli.Command{
|
|
|
|
Name: "api",
|
|
|
|
Description: "start only api",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "listen",
|
|
|
|
Value: ":3000",
|
|
|
|
EnvVars: []string{
|
|
|
|
"LISTEN",
|
|
|
|
"HTTP_LISTEN",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *cli.Context) error {
|
|
|
|
yamlConfig := new(string)
|
|
|
|
*yamlConfig = ctx.String("config")
|
|
|
|
if err := zerocfg.Parse(env.New(), yaml.New(yamlConfig)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start database connection
|
|
|
|
databaseConnection, err := datas.Connect()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start http server
|
2025-05-15 13:03:16 -03:00
|
|
|
return httpserver.ListenAndServe(ctx.String("listen"), router.ApiRouter(databaseConnection))
|
2025-05-05 17:53:00 -03:00
|
|
|
},
|
|
|
|
}
|