From 61237996509487ac7f20eb77b3bac43ef4d6bbb3 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Sat, 16 Sep 2023 17:44:38 -0400 Subject: [PATCH] =?UTF-8?q?Ajouter=20pointers=20=C3=A0=20clients=20en=20pa?= =?UTF-8?q?ram=C3=A8tres=20=C3=A0=20apihandler.New?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apihandler/apihandler.go | 11 +++++++++-- cmd/api.go | 6 ++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/apihandler/apihandler.go b/apihandler/apihandler.go index 8c4bd8e..1339e8e 100644 --- a/apihandler/apihandler.go +++ b/apihandler/apihandler.go @@ -17,8 +17,15 @@ func DeclareRoutes(e *echo.Group, h *APIHandler) { e.GET("/scan/:membre_id/", h.ScanGET) } -func New() (handler APIHandler) { - return +/* +New retourne un nouveau APIHandler contenant des pointers vers les clients +nécessaires à l'exécution du API server +*/ +func New(bottinAPIClient *bottindata.ApiClient, dbClient *dbclient.DBClient) APIHandler { + return APIHandler{ + BottinAPIClient: bottinAPIClient, + DBClient: dbClient, + } } /* diff --git a/cmd/api.go b/cmd/api.go index c55e4b2..d0e5c5b 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -32,16 +32,14 @@ var apiCmd = &cobra.Command{ v0 := e.Group("/v0") - handler := apihandler.New() - - handler.BottinAPIClient = bottindata.NewApiClient("bottin", "localhost", "http", 1312) + 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 + handler := apihandler.New(bottinApiClient, dbClient) if err := handler.DBClient.CreateTablesIfNotExist(); err != nil { log.Fatal(err)