bottin-ag/cmd/api.go

50 lines
992 B
Go
Raw Permalink Normal View History

2023-09-15 13:14:43 -04:00
/*
Copyright © 2023 AGECEM & Victor Lacasse-Beaudoin
*/
package cmd
import (
"fmt"
2023-09-15 16:15:32 -04:00
"log"
2023-09-15 13:14:43 -04:00
"git.agecem.com/agecem/bottin-ag/apihandler"
2023-09-15 16:15:32 -04:00
"git.agecem.com/agecem/bottin-ag/config"
bottindata "git.agecem.com/agecem/bottin/v5/data"
2023-09-15 16:36:56 -04:00
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
2023-09-15 13:14:43 -04:00
"github.com/spf13/cobra"
)
// apiCmd represents the api command
var apiCmd = &cobra.Command{
Use: "api",
Short: "Start the API server",
Run: func(cmd *cobra.Command, args []string) {
cfg, err := config.UnmarshalConfig()
2023-09-15 16:15:32 -04:00
if err != nil {
log.Fatal(err)
}
2023-09-15 16:36:56 -04:00
e := echo.New()
e.Pre(middleware.AddTrailingSlash())
v0 := e.Group("/v0")
handler := apihandler.New()
if &handler == nil {
log.Fatal("Newly created APIHandler is nil")
}
handler.BottinAPIClient = bottindata.NewApiClient("bottin", "localhost", "http", 1312)
apihandler.DeclareRoutes(v0, &handler)
2023-09-15 16:36:56 -04:00
e.Start(fmt.Sprintf(":%d", cfg.API.Port))
2023-09-15 13:14:43 -04:00
},
}
func init() {
rootCmd.AddCommand(apiCmd)
}