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)