Ajouter framework de documentation #35
3 changed files with 13 additions and 55 deletions
|
@ -10,8 +10,6 @@ ADD public/ public/
|
||||||
|
|
||||||
ADD cmd/ cmd/
|
ADD cmd/ cmd/
|
||||||
|
|
||||||
ADD data/ data/
|
|
||||||
|
|
||||||
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o agecem-org .
|
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o agecem-org .
|
||||||
|
|
||||||
# Alpine
|
# Alpine
|
||||||
|
|
|
@ -4,6 +4,7 @@ Copyright © 2023 AGECEM
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"embed"
|
"embed"
|
||||||
|
@ -12,10 +13,11 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
"github.com/minio/minio-go/v7"
|
||||||
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
"git.agecem.com/agecem/agecem-org/data"
|
|
||||||
"git.agecem.com/agecem/agecem-org/public"
|
"git.agecem.com/agecem/agecem-org/public"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/labstack/echo/v4/middleware"
|
"github.com/labstack/echo/v4/middleware"
|
||||||
|
@ -136,17 +138,23 @@ func handleV1Bucket(c echo.Context) error {
|
||||||
documents_secret_access_key := viper.GetString("server.documents.secret_access_key")
|
documents_secret_access_key := viper.GetString("server.documents.secret_access_key")
|
||||||
documents_use_ssl := viper.GetBool("server.documents.use_ssl")
|
documents_use_ssl := viper.GetBool("server.documents.use_ssl")
|
||||||
|
|
||||||
client, err := data.NewClient(documents_buckets, documents_endpoint, documents_access_key_id, documents_secret_access_key, documents_use_ssl)
|
// Initialize minio client object
|
||||||
|
client, err := minio.New(documents_endpoint, &minio.Options{
|
||||||
|
Creds: credentials.NewStaticV4(documents_access_key_id, documents_secret_access_key, ""),
|
||||||
|
Secure: documents_use_ssl,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, err)
|
return c.JSON(http.StatusInternalServerError, map[string]string{
|
||||||
|
"message": "Error during minio#New",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var buckets []string
|
var buckets []string
|
||||||
|
|
||||||
for _, bucket_name := range documents_buckets {
|
for _, bucket_name := range documents_buckets {
|
||||||
exists, err := client.BucketExists(bucket_name)
|
exists, err := client.BucketExists(context.Background(), bucket_name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, err)
|
return c.JSON(http.StatusInternalServerError, "Error during minio#BucketExists")
|
||||||
}
|
}
|
||||||
|
|
||||||
if exists {
|
if exists {
|
||||||
|
|
48
data/data.go
48
data/data.go
|
@ -1,48 +0,0 @@
|
||||||
// Package data provides database interactions to the app
|
|
||||||
package data
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/minio/minio-go/v7"
|
|
||||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Client struct {
|
|
||||||
Endpoint, AccessKeyID, SecretAccessKey string
|
|
||||||
UseSSL bool
|
|
||||||
MinioClient *minio.Client
|
|
||||||
Context context.Context
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewClient(buckets []string, endpoint, accessKeyID, secretAccessKey string, useSSL bool) (*Client, error) {
|
|
||||||
c := Client{
|
|
||||||
Endpoint: endpoint,
|
|
||||||
AccessKeyID: accessKeyID,
|
|
||||||
SecretAccessKey: secretAccessKey,
|
|
||||||
UseSSL: useSSL,
|
|
||||||
Context: context.Background(),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize minio client object
|
|
||||||
minio_client, err := minio.New(endpoint, &minio.Options{
|
|
||||||
Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
|
|
||||||
Secure: useSSL,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return &c, err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.MinioClient = minio_client
|
|
||||||
|
|
||||||
return &c, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) BucketExists(bucketName string) (bool, error) {
|
|
||||||
result, err := c.MinioClient.BucketExists(c.Context, bucketName)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
Loading…
Reference in a new issue