-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
50 lines (38 loc) · 1.33 KB
/
main.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
package main
import (
"log"
"os"
"strings"
"github.com/minio/minio-go"
)
func main() {
minioURL := os.Getenv("MINIO_URL")
accessKey := os.Getenv("ACCESSKEY")
secretKey := os.Getenv("SECRETKEY")
src := os.Getenv("SRC")
dest := os.Getenv("DEST")
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
// dummy values, please replace them with original values.
// Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
// This boolean value is the last argument for New().
// New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically
// determined based on the Endpoint value.
// TODO: fetch this from env vars or config file
minClient, err := minio.New(minioURL, accessKey, secretKey, false)
if err != nil {
log.Fatalln(err)
}
fileParts := strings.Split(src, "/")
bucketName := fileParts[0]
filePath := strings.Join(fileParts[1:], "/")
// first check if specified bucket exists
bucketExists(minClient, bucketName)
// get list of remote file(s) to download
remoteFiles, err := listObjects(minClient, bucketName, filePath)
if err != nil {
log.Fatalln("Error listing objects in ", bucketName, err)
}
log.Println("list of files to check", remoteFiles)
// go get them files
getFiles(minClient, remoteFiles, bucketName, dest)
}