Démarrer echo pour apiCmd et webCmd

This commit is contained in:
Victor Lacasse-Beaudoin 2023-09-15 16:36:56 -04:00
parent cc2e8caddc
commit 2ad3fdf9cb
4 changed files with 86 additions and 11 deletions

View file

@ -8,6 +8,8 @@ import (
"log"
"git.agecem.com/agecem/bottin-ag/config"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/spf13/cobra"
)
@ -21,8 +23,11 @@ var apiCmd = &cobra.Command{
log.Fatal(err)
}
fmt.Println("api called with api-port", cfg.API.Port)
fmt.Println("api called with web-port", cfg.Web.Port)
e := echo.New()
e.Pre(middleware.AddTrailingSlash())
e.Start(fmt.Sprintf(":%d", cfg.API.Port))
},
}

View file

@ -5,7 +5,11 @@ 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"
)
@ -14,7 +18,16 @@ var webCmd = &cobra.Command{
Use: "web",
Short: "Start the webserver",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("web called")
cfg, err := config.GetConfig()
if err != nil {
log.Fatal(err)
}
e := echo.New()
e.Pre(middleware.AddTrailingSlash())
e.Start(fmt.Sprintf(":%d", cfg.Web.Port))
},
}