Victor Lacasse-Beaudoin
309942921d
Ajouter *bottin.Data#ApiClient à APIHandler Implémenter BottinStatus dans apihandler.HealthGET
49 lines
992 B
Go
49 lines
992 B
Go
/*
|
|
Copyright © 2023 AGECEM & Victor Lacasse-Beaudoin
|
|
*/
|
|
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"git.agecem.com/agecem/bottin-ag/apihandler"
|
|
"git.agecem.com/agecem/bottin-ag/config"
|
|
bottindata "git.agecem.com/agecem/bottin/v5/data"
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/labstack/echo/v4/middleware"
|
|
"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()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
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)
|
|
|
|
e.Start(fmt.Sprintf(":%d", cfg.API.Port))
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(apiCmd)
|
|
}
|