From 682d8fc6aae5e6667b1943b1b284b70ddfc0b4a5 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Sat, 16 Sep 2023 17:22:12 -0400 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9er=20tables=20sur=20d=C3=A9marrage=20de?= =?UTF-8?q?=20apiCmd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apihandler/apihandler.go | 2 ++ cmd/api.go | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/apihandler/apihandler.go b/apihandler/apihandler.go index e051ce1..8c4bd8e 100644 --- a/apihandler/apihandler.go +++ b/apihandler/apihandler.go @@ -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` diff --git a/cmd/api.go b/cmd/api.go index 71e1304..c55e4b2 100644 --- a/cmd/api.go +++ b/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))