From dc72748fbe24decb749710c7cfaa4eabee799731 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Fri, 15 Sep 2023 18:13:48 -0400 Subject: [PATCH 1/2] =?UTF-8?q?Impl=C3=A9menter=20route=20/v0/health?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajouter error type si dbclient ou bottinclient ne sont pas implémentés Ajouter echo.Group v0 --- apierror/apierror.go | 8 +++++++ apihandler/apihandler.go | 45 ++++++++++++++++++++++++++++++++++++++ apiresponse/apiresponse.go | 16 ++++++++++++++ cmd/api.go | 7 ++++++ 4 files changed, 76 insertions(+) create mode 100644 apierror/apierror.go diff --git a/apierror/apierror.go b/apierror/apierror.go new file mode 100644 index 0000000..daea8b0 --- /dev/null +++ b/apierror/apierror.go @@ -0,0 +1,8 @@ +// Package apierror defines error types that can be returned by the API server +package apierror + +type ErrBottinOrDBNotImplemented struct{} + +func (e *ErrBottinOrDBNotImplemented) Error() string { + return "Database client or agecem/bottin API client not implemented" +} diff --git a/apihandler/apihandler.go b/apihandler/apihandler.go index f96f1fc..f05fee6 100644 --- a/apihandler/apihandler.go +++ b/apihandler/apihandler.go @@ -1,2 +1,47 @@ // Package apihandler provides handlers for API routes package apihandler + +import ( + "net/http" + + "git.agecem.com/agecem/bottin-ag/apierror" + "git.agecem.com/agecem/bottin-ag/apiresponse" + "github.com/labstack/echo/v4" +) + +// DeclareRoutes declares the API server endpoints for the specified Group +func DeclareRoutes(e *echo.Group, h *APIHandler) { + e.GET("/health/", h.HealthGET) +} + +func New() (handler *APIHandler) { + return +} + +/* +APIHandler is the struct that implements the actual logic for the API server +routes +*/ +type APIHandler struct{} + +// HealthGET is the handler for `GET /v:version/health/ http/1.1` +func (a *APIHandler) HealthGET(c echo.Context) error { + var r apiresponse.HealthGET + + // TODO + r.Data.BottinStatus = "not implemented" + + // TODO + r.Data.DBStatus = "not implemented" + + if r.Data.BottinStatus == "not implemented" || r.Data.DBStatus == "not implemented" { + var err apierror.ErrBottinOrDBNotImplemented + r.Error = err.Error() + r.StatusCode = http.StatusInternalServerError + r.Message = "not ok" + + return c.JSON(r.StatusCode, r) + } + + return c.JSON(r.StatusCode, r) +} diff --git a/apiresponse/apiresponse.go b/apiresponse/apiresponse.go index 5b2b319..9d454d4 100644 --- a/apiresponse/apiresponse.go +++ b/apiresponse/apiresponse.go @@ -1,2 +1,18 @@ // Package apiresponse provides response types for API routes package apiresponse + +// Response defines the basic response types fields +type Response struct { + Error string + Message string + StatusCode int +} + +// HealthGET is the response type for `GET /v:version/health/ http/1.1` +type HealthGET struct { + Response + Data struct { + BottinStatus string + DBStatus string + } +} diff --git a/cmd/api.go b/cmd/api.go index c305bf1..023801e 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -7,6 +7,7 @@ import ( "fmt" "log" + "git.agecem.com/agecem/bottin-ag/apihandler" "git.agecem.com/agecem/bottin-ag/config" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" @@ -27,6 +28,12 @@ var apiCmd = &cobra.Command{ e.Pre(middleware.AddTrailingSlash()) + v0 := e.Group("/v0") + + handler := apihandler.New() + + apihandler.DeclareRoutes(v0, handler) + e.Start(fmt.Sprintf(":%d", cfg.API.Port)) }, } From 2bae4f5312b3d1ff7ac520d6c6089e6f5a672d2b Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Fri, 15 Sep 2023 18:16:39 -0400 Subject: [PATCH 2/2] =?UTF-8?q?Update=20Dockerfile=20avec=20packages=20pr?= =?UTF-8?q?=C3=A9sents?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index b799bef..3e11ae5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,13 +6,15 @@ WORKDIR /go/src/app COPY go.mod go.sum main.go ./ +ADD apiclient/ apiclient/ +ADD apierror/ apierror/ +ADD apihandler/ apihandler/ +ADD apiresponse/ apiresponse/ ADD cmd/ cmd/ ADD config/ config/ -ADD data/ data/ -ADD handlers/ handlers/ -ADD models/ models/ -ADD responses/ responses/ -ADD templates/ templates/ +ADD dbclient/ dbclient/ +ADD webcontent/ webcontent/ +ADD webhandler/ webhandler/ RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o bottin-ag .