Démarrer echo pour apiCmd et webCmd
This commit is contained in:
parent
cc2e8caddc
commit
2ad3fdf9cb
4 changed files with 86 additions and 11 deletions
|
@ -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))
|
||||
},
|
||||
}
|
||||
|
||||
|
|
15
cmd/web.go
15
cmd/web.go
|
@ -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))
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue