From 8f5d3794f481db5e7b76a99ebe70a20089d9fdca Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Fri, 21 Apr 2023 18:36:20 -0400 Subject: [PATCH] Remplacer /v1/health par /v1/bucket /v1/health pourra revenir plus tard, pour l'instant le healthcheck ne fonctionne pas bien. Ajouter listing de buckets valides par `GET /v1/bucket` --- cmd/server.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/cmd/server.go b/cmd/server.go index f7e323c..90e2aac 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -84,7 +84,7 @@ func RunServer() { e.GET("/v1", handleV1) - e.GET("/v1/health", handleV1Health) + e.GET("/v1/bucket", handleV1Bucket) // Static Routes @@ -128,10 +128,9 @@ func handleV1(c echo.Context) error { return c.JSON(http.StatusOK, routes) } -// handleV1Health affiche l'état de connexion à la base de données -func handleV1Health(c echo.Context) error { +// handleV1Bucket affiche les buckets permis par server.documents.buckets, qui existent. +func handleV1Bucket(c echo.Context) error { documents_buckets := viper.GetStringSlice("server.documents.buckets") - documents_endpoint := viper.GetString("server.documents.endpoint") documents_access_key_id := viper.GetString("server.documents.access_key_id") documents_secret_access_key := viper.GetString("server.documents.secret_access_key") @@ -142,21 +141,20 @@ func handleV1Health(c echo.Context) error { return c.JSON(http.StatusInternalServerError, err) } - if len(documents_buckets) == 0 { - return c.JSON(http.StatusOK, nil) - } - - message := make(map[string]interface{}, len(documents_buckets)) + var buckets []string for _, bucket_name := range documents_buckets { exists, err := client.BucketExists(bucket_name) if err != nil { return c.JSON(http.StatusInternalServerError, err) } - message[bucket_name] = exists + + if exists { + buckets = append(buckets, bucket_name) + } } - return c.JSON(http.StatusOK, message) + return c.JSON(http.StatusOK, buckets) } // HTML Handlers