Ajouter framework de documentation #35
1 changed files with 9 additions and 11 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue