fixed
This commit is contained in:
1 parent
4194cef934
commit
363127fe9e
3350 files changed
+1284220
-1
No files matched your search
@@ -0,0 +1,49 @@
|
||||
package minio
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
)
|
||||
|
||||
// Must match deployment/Dockerfile.minio MINIO_ROOT_USER / MINIO_ROOT_PASSWORD.
|
||||
const (
|
||||
BucketName = "dev-minio"
|
||||
endpoint = "main-minio:9000"
|
||||
accessKeyID = "MINIO_ROOT_USER"
|
||||
secretAccessKey = "MINIO_ROOT_PASSWORD"
|
||||
)
|
||||
|
||||
func ConnectionMinio() (*minio.Client, error) {
|
||||
minioClient, errInit := minio.New(endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
|
||||
Secure: false,
|
||||
})
|
||||
if errInit != nil {
|
||||
fmt.Println("minio connection:", errInit)
|
||||
return nil, errInit
|
||||
}
|
||||
return minioClient, nil
|
||||
}
|
||||
|
||||
// EnsureBucket creates the app bucket when it does not exist yet.
|
||||
func EnsureBucket(ctx context.Context, client *minio.Client) error {
|
||||
exists, err := client.BucketExists(ctx, BucketName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("bucket exists check: %w", err)
|
||||
}
|
||||
if exists {
|
||||
return nil
|
||||
}
|
||||
if err := client.MakeBucket(ctx, BucketName, minio.MakeBucketOptions{}); err != nil {
|
||||
// Another request may have created it concurrently.
|
||||
exists, checkErr := client.BucketExists(ctx, BucketName)
|
||||
if checkErr == nil && exists {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("make bucket: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user