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