-
Notifications
You must be signed in to change notification settings - Fork 0
/
minio.go
52 lines (44 loc) · 1.26 KB
/
minio.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
41
42
43
44
45
46
47
48
49
50
51
52
package cmd
import (
"context"
"fmt"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
)
func setMinioClient(c S3Config) *minio.Client {
// TODO implement optional port-forward
// see https://stackoverflow.com/questions/59027739/upgrading-connection-error-in-port-forwarding-via-client-go
token := ""
// Initialize minio client object.
minioClient, err := minio.New(c.Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(c.AccessKeyID, c.SecretAccessKey, token),
Secure: c.UseSSL,
})
if err != nil {
logger.Fatalf("Unable to create minio client: %s", err)
}
return minioClient
}
func listBucket(minioClient *minio.Client) {
buckets, err := minioClient.ListBuckets(context.Background())
if err != nil {
logger.Fatal(err)
}
for _, bucket := range buckets {
fmt.Println(bucket)
}
}
func bucketExists(minioClient *minio.Client, bucketName string) bool {
found, err := minioClient.BucketExists(context.Background(), bucketName)
if err != nil {
logger.Fatal(err)
}
return found
}
func makeBucket(minioClient *minio.Client, bucketName string) {
err := minioClient.MakeBucket(context.Background(), bucketName,
minio.MakeBucketOptions{Region: "us-east-1", ObjectLocking: true})
if err != nil {
logger.Fatal(err)
}
}