2023-04-21 16:41:50 -04:00
|
|
|
// 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
|
2023-04-21 17:11:06 -04:00
|
|
|
MinioClient *minio.Client
|
2023-04-21 16:41:50 -04:00
|
|
|
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
|
2023-04-21 17:11:06 -04:00
|
|
|
minio_client, err := minio.New(endpoint, &minio.Options{
|
2023-04-21 16:41:50 -04:00
|
|
|
Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
|
|
|
|
Secure: useSSL,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return &c, err
|
|
|
|
}
|
|
|
|
|
2023-04-21 17:11:06 -04:00
|
|
|
c.MinioClient = minio_client
|
2023-04-21 16:41:50 -04:00
|
|
|
|
|
|
|
return &c, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) BucketExists(bucketName string) (bool, error) {
|
2023-04-21 17:11:06 -04:00
|
|
|
result, err := c.MinioClient.BucketExists(c.Context, bucketName)
|
2023-04-21 16:41:50 -04:00
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|