-
Notifications
You must be signed in to change notification settings - Fork 2
/
fs.go
40 lines (33 loc) · 990 Bytes
/
fs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package fs
import (
"context"
"fmt"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
)
// New create a connection to minio to use as a file storage.
func New(cfg Config) (*minio.Client, error) {
// initialize minio client object.
// nolint: exhaustruct
client, err := minio.New(cfg.Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(cfg.AccessKey, cfg.SecretKey, ""),
Secure: cfg.UseSSL,
})
if err != nil {
return nil, fmt.Errorf("minio connection failed: %w", err)
}
return client, nil
}
func Bucket(ctx context.Context, client *minio.Client, bucket string) error {
found, err := client.BucketExists(ctx, bucket)
if err != nil {
return fmt.Errorf("cannot check minio bucket [%s] existence: %w", bucket, err)
}
if !found {
// nolint: exhaustruct
if err := client.MakeBucket(ctx, bucket, minio.MakeBucketOptions{}); err != nil {
return fmt.Errorf("cannot make minio bucket [%s]: %w", bucket, err)
}
}
return nil
}