diff --git a/Dockerfile b/Dockerfile index 6b6f422..0e98d5c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,6 @@ ADD public/ public/ ADD cmd/ cmd/ -ADD data/ data/ - RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o agecem-org . # Alpine diff --git a/cmd/server.go b/cmd/server.go index 90e2aac..8c85c28 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -4,6 +4,7 @@ Copyright © 2023 AGECEM package cmd import ( + "context" "fmt" "embed" @@ -12,10 +13,11 @@ import ( "net/http" "sort" + "github.com/minio/minio-go/v7" + "github.com/minio/minio-go/v7/pkg/credentials" "github.com/spf13/cobra" "github.com/spf13/viper" - "git.agecem.com/agecem/agecem-org/data" "git.agecem.com/agecem/agecem-org/public" "github.com/labstack/echo/v4" "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_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 { - return c.JSON(http.StatusInternalServerError, err) + return c.JSON(http.StatusInternalServerError, map[string]string{ + "message": "Error during minio#New", + }) } var buckets []string for _, bucket_name := range documents_buckets { - exists, err := client.BucketExists(bucket_name) + exists, err := client.BucketExists(context.Background(), bucket_name) if err != nil { - return c.JSON(http.StatusInternalServerError, err) + return c.JSON(http.StatusInternalServerError, "Error during minio#BucketExists") } if exists { diff --git a/data/data.go b/data/data.go deleted file mode 100644 index 4c6fd2e..0000000 --- a/data/data.go +++ /dev/null @@ -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 -}