Bump API à version 2 #2
6 changed files with 31 additions and 29 deletions
13
cmd/api.go
13
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
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
2
go.mod
2
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
|
||||
|
|
4
go.sum
4
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=
|
||||
|
|
|
@ -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{
|
|
@ -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 {
|
||||
|
|
Reference in a new issue