Victor Lacasse-Beaudoin
28cc97dcee
Ajouter data/ Ajouter data/ à Dockerfile Ajouter flags pour server.port et server.documents.* Ajouter viper Ajouter example de config à examples/config/ Exécuter serveur sur port custom (8080 par défaut) Retirer copyright notice de main.go Cleanup dependencies (go get, go mod tidy) Ajouter /v1/health Ajouter container minio à docker-compose
48 lines
1.1 KiB
Go
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
|
|
MongoClient *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
|
|
mongo_client, err := minio.New(endpoint, &minio.Options{
|
|
Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
|
|
Secure: useSSL,
|
|
})
|
|
if err != nil {
|
|
return &c, err
|
|
}
|
|
|
|
c.MongoClient = mongo_client
|
|
|
|
return &c, nil
|
|
}
|
|
|
|
func (c *Client) BucketExists(bucketName string) (bool, error) {
|
|
result, err := c.MongoClient.BucketExists(c.Context, bucketName)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return result, nil
|
|
}
|