bottin-ag/cmd/api.go

36 lines
627 B
Go

/*
Copyright © 2023 AGECEM & Victor Lacasse-Beaudoin
*/
package cmd
import (
"fmt"
"log"
"git.agecem.com/agecem/bottin-ag/config"
"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.GetConfig()
if err != nil {
log.Fatal(err)
}
e := echo.New()
e.Pre(middleware.AddTrailingSlash())
e.Start(fmt.Sprintf(":%d", cfg.API.Port))
},
}
func init() {
rootCmd.AddCommand(apiCmd)
}