-
Notifications
You must be signed in to change notification settings - Fork 2
/
bucket.go
43 lines (34 loc) · 962 Bytes
/
bucket.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
package main
import (
"log"
minio "github.com/minio/minio-go"
)
// Checking if a bucket exists
func bucketExists(client *minio.Client, bucketName string) {
found, err := client.BucketExists(bucketName)
if err != nil {
log.Fatalln(err)
}
if found {
log.Println(bucketName, "Bucket found.")
} else {
log.Fatalln("Bucket not found -", bucketName)
}
}
// listing objects in a bucket
func listObjects(client *minio.Client, bucketName, filePath string) ([]string, error) {
// Create a done channel to control 'ListObjectsV2' go routine.
doneCh := make(chan struct{})
// Indicate to our routine to exit cleanly upon return.
defer close(doneCh)
isRecursive := true
objectCh := client.ListObjectsV2(bucketName, filePath, isRecursive, doneCh)
remoteFiles := []string{}
for object := range objectCh {
if object.Err != nil {
return remoteFiles, object.Err
}
remoteFiles = append(remoteFiles, object.Key)
}
return remoteFiles, nil
}