diff --git a/cmd/api.go b/cmd/api.go index f36c18b..397d2cc 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -6,7 +6,7 @@ import ( "log" "git.agecem.com/agecem/bottin-agenda/handlers" - bottindata "git.agecem.com/agecem/bottin/v4/data" + bottindata "git.agecem.com/agecem/bottin/v5/data" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" "github.com/spf13/cobra" @@ -64,19 +64,18 @@ var apiCmd = &cobra.Command{ // Routes - e.GET("/v2/", handlers.GetV2) + e.GET("/v2/health/", handlers.GetHealth) - e.GET("/v2/membres/:membre_id", handlers.GetMembre) + e.GET("/v2/membres/:membre_id/", handlers.GetMembre) // Check bottin is ready - message, err := bottinConnection.GetV4() + bottinHealthResponse, err := bottinConnection.GetHealth() if err != nil { - log.Fatal(err) + log.Fatalf("bottinConnection.GetHealth(): %s", err) } - //TODO - log.Println(message) + log.Println(bottinHealthResponse) // Execution diff --git a/data/apiclient.go b/data/apiclient.go index 5f36780..f0f1453 100644 --- a/data/apiclient.go +++ b/data/apiclient.go @@ -67,33 +67,36 @@ func (a *ApiClient) Call(method, route string, requestBody io.Reader, useKey boo return response, nil } -// GetV4 allows checking for API v4 server health -func (a *ApiClient) GetV4() (string, error) { - var getV4Response struct { - Message string `json:"message"` - } +// BottinHealthResponse is the response type for GetBottinHealth +type BottinHealthResponse struct { + Message string `json:"message"` +} - response, err := a.Call(http.MethodGet, "/v4", nil, true) +// GetHealth allows checking for API server health +func (a *ApiClient) GetBottinHealth() (string, error) { + var healthResponse BottinHealthResponse + + response, err := a.Call(http.MethodGet, "/v4/health", nil, true) if err != nil { - return getV4Response.Message, err + return healthResponse.Message, err } defer response.Body.Close() body, err := ioutil.ReadAll(response.Body) if err != nil { - return getV4Response.Message, err + return healthResponse.Message, err } - if err := json.Unmarshal(body, &getV4Response); err != nil { - return getV4Response.Message, err + if err := json.Unmarshal(body, &healthResponse); err != nil { + return healthResponse.Message, err } - if getV4Response.Message == "" { - return getV4Response.Message, errors.New("Could not confirm that API server is up, no response message") + if healthResponse.Message == "" { + return healthResponse.Message, errors.New("Could not confirm that API server is up, no response message") } - return getV4Response.Message, nil + return healthResponse.Message, nil } /* diff --git a/go.mod b/go.mod index e361a00..4ea90d2 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.agecem.com/agecem/bottin-agenda go 1.20 require ( - git.agecem.com/agecem/bottin/v4 v4.1.0 + git.agecem.com/agecem/bottin/v5 v5.0.4 github.com/jackc/pgx v3.6.2+incompatible github.com/jmoiron/sqlx v1.3.5 github.com/labstack/echo/v4 v4.10.2 diff --git a/go.sum b/go.sum index 24872b2..77145a2 100644 --- a/go.sum +++ b/go.sum @@ -36,8 +36,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -git.agecem.com/agecem/bottin/v4 v4.1.0 h1:S8Mrh/pJaH5b0LbJkV7edFNyF+BJ1OZ7pYAccUUcv28= -git.agecem.com/agecem/bottin/v4 v4.1.0/go.mod h1:U7jxx83B4D7ST1GP+0tvCrAkMtC0s1Qgvv1NvCIg8CQ= +git.agecem.com/agecem/bottin/v5 v5.0.4 h1:19xQjnc9cZU1vBtk9mjhQ8QDg4nlpYLShmkbUeptVbM= +git.agecem.com/agecem/bottin/v5 v5.0.4/go.mod h1:OGqwTvEtIEOg/AHZgaJPzsMCy94dWygq89rMJlCFLuU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/handlers/v2.go b/handlers/health.go similarity index 73% rename from handlers/v2.go rename to handlers/health.go index 9a02ca0..9364932 100644 --- a/handlers/v2.go +++ b/handlers/health.go @@ -3,18 +3,18 @@ package handlers import ( "net/http" - "git.agecem.com/agecem/bottin-agenda/data" + bottindata "git.agecem.com/agecem/bottin/v5/data" "github.com/labstack/echo/v4" "github.com/spf13/viper" ) -func GetV2(c echo.Context) error { +func GetHealth(c echo.Context) error { bottinApiKey := viper.GetString("bottin.api.key") bottinApiHost := viper.GetString("bottin.api.host") bottinApiProtocol := viper.GetString("bottin.api.protocol") bottinApiPort := viper.GetInt("bottin.api.port") - bottinConnection := data.NewApiClient( + bottinConnection := bottindata.NewApiClient( bottinApiKey, bottinApiHost, bottinApiProtocol, @@ -23,11 +23,11 @@ func GetV2(c echo.Context) error { var bottinStatus string - message, err := bottinConnection.GetV4() + healthResponse, err := bottinConnection.GetHealth() if err != nil { bottinStatus = err.Error() } else { - bottinStatus = message + bottinStatus = healthResponse } return c.JSON(http.StatusOK, map[string]string{ diff --git a/handlers/membre.go b/handlers/membre.go index 5ef8c08..3b8286c 100644 --- a/handlers/membre.go +++ b/handlers/membre.go @@ -6,7 +6,7 @@ import ( "github.com/labstack/echo/v4" "github.com/spf13/viper" - bottindata "git.agecem.com/agecem/bottin/v4/data" + bottindata "git.agecem.com/agecem/bottin/v5/data" ) func GetMembre(c echo.Context) error {