Ajouter pointers à clients en paramètres à apihandler.New

This commit is contained in:
Victor Lacasse-Beaudoin 2023-09-16 17:44:38 -04:00
parent 682d8fc6aa
commit 6123799650
2 changed files with 11 additions and 6 deletions

View file

@ -17,8 +17,15 @@ func DeclareRoutes(e *echo.Group, h *APIHandler) {
e.GET("/scan/:membre_id/", h.ScanGET) 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,
}
} }
/* /*

View file

@ -32,16 +32,14 @@ var apiCmd = &cobra.Command{
v0 := e.Group("/v0") v0 := e.Group("/v0")
handler := apihandler.New() bottinApiClient := bottindata.NewApiClient("bottin", "localhost", "http", 1312)
handler.BottinAPIClient = bottindata.NewApiClient("bottin", "localhost", "http", 1312)
dbClient, err := dbclient.New("db", "bottinag", "bottinag", "bottinag", 5432, false) dbClient, err := dbclient.New("db", "bottinag", "bottinag", "bottinag", 5432, false)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
handler.DBClient = dbClient handler := apihandler.New(bottinApiClient, dbClient)
if err := handler.DBClient.CreateTablesIfNotExist(); err != nil { if err := handler.DBClient.CreateTablesIfNotExist(); err != nil {
log.Fatal(err) log.Fatal(err)