Créer tables sur démarrage de apiCmd
This commit is contained in:
parent
a88809f91e
commit
682d8fc6aa
2 changed files with 14 additions and 0 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"git.agecem.com/agecem/bottin-ag/apiresponse"
|
||||
"git.agecem.com/agecem/bottin-ag/dbclient"
|
||||
bottindata "git.agecem.com/agecem/bottin/v5/data"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
@ -26,6 +27,7 @@ routes
|
|||
*/
|
||||
type APIHandler struct {
|
||||
BottinAPIClient *bottindata.ApiClient
|
||||
DBClient *dbclient.DBClient
|
||||
}
|
||||
|
||||
// HealthGET is the handler for `GET /v:version/health/ http/1.1`
|
||||
|
|
12
cmd/api.go
12
cmd/api.go
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"git.agecem.com/agecem/bottin-ag/apihandler"
|
||||
"git.agecem.com/agecem/bottin-ag/config"
|
||||
"git.agecem.com/agecem/bottin-ag/dbclient"
|
||||
bottindata "git.agecem.com/agecem/bottin/v5/data"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
|
@ -35,6 +36,17 @@ var apiCmd = &cobra.Command{
|
|||
|
||||
handler.BottinAPIClient = bottindata.NewApiClient("bottin", "localhost", "http", 1312)
|
||||
|
||||
dbClient, err := dbclient.New("db", "bottinag", "bottinag", "bottinag", 5432, false)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
handler.DBClient = dbClient
|
||||
|
||||
if err := handler.DBClient.CreateTablesIfNotExist(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
apihandler.DeclareRoutes(v0, &handler)
|
||||
|
||||
e.Start(fmt.Sprintf(":%d", cfg.API.Port))
|
||||
|
|
Loading…
Reference in a new issue