From 412727bf9c6728260be0c9ceafda9cfaabc7c5c0 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Fri, 2 Jun 2023 16:08:08 -0400 Subject: [PATCH 1/5] Fix local imports --- cmd/api.go | 4 ++-- cmd/web.go | 6 +++--- data/apiclient.go | 2 +- data/data.go | 2 +- go.mod | 2 +- handlers/health.go | 2 +- handlers/insert.go | 4 ++-- handlers/read.go | 2 +- handlers/seed.go | 2 +- handlers/update.go | 2 +- main.go | 2 +- web/webhandlers/handlers.go | 2 +- 12 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cmd/api.go b/cmd/api.go index 5c2ce60..f1988b6 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -5,8 +5,8 @@ import ( "fmt" "log" - "git.agecem.com/agecem/bottin/v4/data" - "git.agecem.com/agecem/bottin/v4/handlers" + "git.agecem.com/agecem/bottin/data" + "git.agecem.com/agecem/bottin/handlers" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" "github.com/spf13/cobra" diff --git a/cmd/web.go b/cmd/web.go index 08f6375..adf7de3 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -8,9 +8,9 @@ import ( "io" "log" - "git.agecem.com/agecem/bottin/v4/data" - "git.agecem.com/agecem/bottin/v4/web" - "git.agecem.com/agecem/bottin/v4/web/webhandlers" + "git.agecem.com/agecem/bottin/data" + "git.agecem.com/agecem/bottin/web" + "git.agecem.com/agecem/bottin/web/webhandlers" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" "github.com/spf13/cobra" diff --git a/data/apiclient.go b/data/apiclient.go index 9fc1d5a..7143204 100644 --- a/data/apiclient.go +++ b/data/apiclient.go @@ -8,7 +8,7 @@ import ( "io/ioutil" "net/http" - "git.agecem.com/agecem/bottin/v4/models" + "git.agecem.com/agecem/bottin/models" "github.com/spf13/viper" ) diff --git a/data/data.go b/data/data.go index 9601792..5494cb1 100644 --- a/data/data.go +++ b/data/data.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "git.agecem.com/agecem/bottin/v4/models" + "git.agecem.com/agecem/bottin/models" _ "github.com/jackc/pgx/stdlib" "github.com/jmoiron/sqlx" "github.com/spf13/viper" diff --git a/go.mod b/go.mod index b6a59fc..5963afa 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module git.agecem.com/agecem/bottin/v4 +module git.agecem.com/agecem/bottin go 1.20 diff --git a/handlers/health.go b/handlers/health.go index 49d45b0..99cc498 100644 --- a/handlers/health.go +++ b/handlers/health.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - "git.agecem.com/agecem/bottin/v4/data" + "git.agecem.com/agecem/bottin/data" "github.com/labstack/echo/v4" ) diff --git a/handlers/insert.go b/handlers/insert.go index 629d6e7..38cad02 100644 --- a/handlers/insert.go +++ b/handlers/insert.go @@ -3,8 +3,8 @@ package handlers import ( "net/http" - "git.agecem.com/agecem/bottin/v4/data" - "git.agecem.com/agecem/bottin/v4/models" + "git.agecem.com/agecem/bottin/data" + "git.agecem.com/agecem/bottin/models" "github.com/labstack/echo/v4" "github.com/spf13/viper" ) diff --git a/handlers/read.go b/handlers/read.go index 8136e21..3932ec3 100644 --- a/handlers/read.go +++ b/handlers/read.go @@ -3,7 +3,7 @@ package handlers import ( "net/http" - "git.agecem.com/agecem/bottin/v4/data" + "git.agecem.com/agecem/bottin/data" "github.com/labstack/echo/v4" "github.com/spf13/viper" ) diff --git a/handlers/seed.go b/handlers/seed.go index 91d5037..237de09 100644 --- a/handlers/seed.go +++ b/handlers/seed.go @@ -3,7 +3,7 @@ package handlers import ( "net/http" - "git.agecem.com/agecem/bottin/v4/data" + "git.agecem.com/agecem/bottin/data" "github.com/labstack/echo/v4" "github.com/spf13/viper" ) diff --git a/handlers/update.go b/handlers/update.go index 8a8cf0a..6422f61 100644 --- a/handlers/update.go +++ b/handlers/update.go @@ -3,7 +3,7 @@ package handlers import ( "net/http" - "git.agecem.com/agecem/bottin/v4/data" + "git.agecem.com/agecem/bottin/data" "github.com/labstack/echo/v4" "github.com/spf13/viper" ) diff --git a/main.go b/main.go index 6ceb837..c6efc0b 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,6 @@ package main -import "git.agecem.com/agecem/bottin/v4/cmd" +import "git.agecem.com/agecem/bottin/cmd" func main() { cmd.Execute() diff --git a/web/webhandlers/handlers.go b/web/webhandlers/handlers.go index 732d3e7..abfa955 100644 --- a/web/webhandlers/handlers.go +++ b/web/webhandlers/handlers.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - "git.agecem.com/agecem/bottin/v4/data" + "git.agecem.com/agecem/bottin/data" "github.com/labstack/echo/v4" ) -- 2.45.2 From 883edccf8703628f9dd4723f9ae086f72f3809ef Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Fri, 2 Jun 2023 16:16:18 -0400 Subject: [PATCH 2/5] Cleanup dataclient pour cmd/api Utiliser NewDataClientFromViper --- cmd/api.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/cmd/api.go b/cmd/api.go index f1988b6..a7317b1 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -27,14 +27,6 @@ var apiCmd = &cobra.Command{ apiKey = viper.GetString("api.key") apiPort = viper.GetInt("api.port") - connection := data.PostgresConnection{ - User: viper.GetString("db.user"), - Password: viper.GetString("db.password"), - Host: viper.GetString("db.host"), - Database: viper.GetString("db.database"), - Port: viper.GetInt("db.port"), - } - e := echo.New() // Middlewares @@ -63,7 +55,7 @@ var apiCmd = &cobra.Command{ // Execution - client, err := data.NewDataClient(connection) + client, err := data.NewDataClientFromViper() if err != nil { log.Fatalf("Could not establish database connection.\n Error: %s\n", err) } -- 2.45.2 From 9ac95672b9381b99e7f02e713fe555b5e221d072 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Fri, 2 Jun 2023 16:21:14 -0400 Subject: [PATCH 3/5] Fix ApiClient.GetHealth Utiliser type handlers.GetHealthResponse Pointer vers route /v4/health --- data/apiclient.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/data/apiclient.go b/data/apiclient.go index 7143204..21ceecc 100644 --- a/data/apiclient.go +++ b/data/apiclient.go @@ -8,6 +8,7 @@ import ( "io/ioutil" "net/http" + "git.agecem.com/agecem/bottin/handlers" "git.agecem.com/agecem/bottin/models" "github.com/spf13/viper" ) @@ -79,33 +80,31 @@ 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"` - } +// GetHealth allows checking for API server health +func (a *ApiClient) GetHealth() (string, error) { + var getHealthResponse handlers.GetHealthResponse - response, err := a.Call(http.MethodGet, "/v4", nil, true) + response, err := a.Call(http.MethodGet, "/v4/health", nil, true) if err != nil { - return getV4Response.Message, err + return getHealthResponse.Message, err } defer response.Body.Close() body, err := ioutil.ReadAll(response.Body) if err != nil { - return getV4Response.Message, err + return getHealthResponse.Message, err } - if err := json.Unmarshal(body, &getV4Response); err != nil { - return getV4Response.Message, err + if err := json.Unmarshal(body, &getHealthResponse); err != nil { + return getHealthResponse.Message, err } - if getV4Response.Message == "" { - return getV4Response.Message, errors.New("Could not confirm that API server is up, no response message") + if getHealthResponse.Message == "" { + return getHealthResponse.Message, errors.New("Could not confirm that API server is up, no response message") } - return getV4Response.Message, nil + return getHealthResponse.Message, nil } func (a *ApiClient) GetMembre(membreID string) (models.Membre, error) { -- 2.45.2 From 764093f99d2993db8df7ab6773b5b39c539f8928 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Fri, 2 Jun 2023 16:33:13 -0400 Subject: [PATCH 4/5] Bump routes v4 -> v5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remplacer références GetV4 -> GetHealth Ajouter package responses Remplacer handlers.GetHealthResponse -> responses.GetHealth --- cmd/api.go | 12 ++++++------ cmd/web.go | 2 +- data/apiclient.go | 8 ++++---- handlers/health.go | 9 +++------ responses/health.go | 6 ++++++ 5 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 responses/health.go diff --git a/cmd/api.go b/cmd/api.go index a7317b1..1044c34 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -41,17 +41,17 @@ var apiCmd = &cobra.Command{ // Routes - e.GET("/v4/health/", handlers.GetHealth) + e.GET("/v5/health/", handlers.GetHealth) - e.POST("/v4/membres/", handlers.PostMembres) + e.POST("/v5/membres/", handlers.PostMembres) - e.GET("/v4/membres/:membre_id/", handlers.ReadMembre) + e.GET("/v5/membres/:membre_id/", handlers.ReadMembre) - e.PUT("/v4/membres/:membre_id/prefered_name/", handlers.PutMembrePreferedName) + e.PUT("/v5/membres/:membre_id/prefered_name/", handlers.PutMembrePreferedName) - e.POST("/v4/programmes/", handlers.PostProgrammes) + e.POST("/v5/programmes/", handlers.PostProgrammes) - e.POST("/v4/seed/", handlers.PostSeed) + e.POST("/v5/seed/", handlers.PostSeed) // Execution diff --git a/cmd/web.go b/cmd/web.go index adf7de3..c773b56 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -55,7 +55,7 @@ var webCmd = &cobra.Command{ apiClient := data.NewApiClient(webApiKey, webApiHost, webApiProtocol, webApiPort) - pingResult, err := apiClient.GetV4() + pingResult, err := apiClient.GetHealth() if err != nil { log.Fatal(err) } diff --git a/data/apiclient.go b/data/apiclient.go index 21ceecc..1eef66a 100644 --- a/data/apiclient.go +++ b/data/apiclient.go @@ -8,8 +8,8 @@ import ( "io/ioutil" "net/http" - "git.agecem.com/agecem/bottin/handlers" "git.agecem.com/agecem/bottin/models" + "git.agecem.com/agecem/bottin/responses" "github.com/spf13/viper" ) @@ -82,9 +82,9 @@ func (a *ApiClient) Call(method, route string, requestBody io.Reader, useKey boo // GetHealth allows checking for API server health func (a *ApiClient) GetHealth() (string, error) { - var getHealthResponse handlers.GetHealthResponse + var getHealthResponse responses.GetHealth - response, err := a.Call(http.MethodGet, "/v4/health", nil, true) + response, err := a.Call(http.MethodGet, "/v5/health", nil, true) if err != nil { return getHealthResponse.Message, err } @@ -124,7 +124,7 @@ func (a *ApiClient) GetMembre(membreID string) (models.Membre, error) { log.Println("ApiClient.GetMembre received membreID: ", membreID) */ - response, err := a.Call(http.MethodGet, fmt.Sprintf("/v4/membres/%s", membreID), nil, true) + response, err := a.Call(http.MethodGet, fmt.Sprintf("/v5/membres/%s", membreID), nil, true) if err != nil { return getMembreResponse.Data.Membre, err } diff --git a/handlers/health.go b/handlers/health.go index 99cc498..5292e56 100644 --- a/handlers/health.go +++ b/handlers/health.go @@ -5,16 +5,13 @@ import ( "net/http" "git.agecem.com/agecem/bottin/data" + "git.agecem.com/agecem/bottin/responses" "github.com/labstack/echo/v4" ) -type GetHealthResponse struct { - Message string `json:"message"` -} - func GetHealth(c echo.Context) error { - response := GetHealthResponse{ - Message: "Bottin API v4 is ready", + response := responses.GetHealth{ + Message: "Bottin API v5 is ready", } dataClient, err := data.NewDataClientFromViper() diff --git a/responses/health.go b/responses/health.go new file mode 100644 index 0000000..6d5e663 --- /dev/null +++ b/responses/health.go @@ -0,0 +1,6 @@ +package responses + +// GetHealth is the response type for handlers.GetHealth +type GetHealth struct { + Message string `json:"message"` +} -- 2.45.2 From b45c074a120d6cc869b7cbe31c402ece501c669c Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Fri, 2 Jun 2023 16:36:08 -0400 Subject: [PATCH 5/5] =?UTF-8?q?Ajouter=20responses/=20=C3=A0=20build=20ste?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 805727f..23820d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ ADD cmd/ cmd/ ADD data/ data/ ADD handlers/ handlers/ ADD models/ models/ +ADD responses/ responses/ ADD web/ web/ RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o bottin . -- 2.45.2