agecem-org/data/data.go
Victor Lacasse-Beaudoin a3287768ad Replace MongoClient with MinioClient (was typo)
Use bucket_name instead of bucket in handleV1Health
2023-04-21 17:11:06 -04:00

48 lines
1.1 KiB
Go

// 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
}