-
Notifications
You must be signed in to change notification settings - Fork 1
/
s3.go
44 lines (41 loc) · 1.15 KB
/
s3.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
package main
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3"
"strings"
"time"
)
func loadS3Files(conf *Config, buffer int, logger *Logger) chan *FileStat {
out := make(chan *FileStat, buffer)
go func() {
start := time.Now()
logger.Debug.Printf("read s3 - start at %s", start)
continuationToken := listS3Files(conf, out, nil)
for continuationToken != nil {
continuationToken = listS3Files(conf, out, continuationToken)
}
logger.Debug.Printf("read s3 - stop, it took %s", time.Since(start))
close(out)
}()
return out
}
func listS3Files(config *Config, out chan *FileStat, token *string) *string {
list, err := config.S3Service.ListObjectsV2(&s3.ListObjectsV2Input{
Bucket: aws.String(config.Bucket),
Prefix: aws.String(config.BucketPrefix),
ContinuationToken: token,
})
if err != nil {
out <- &FileStat{Err: err}
return nil
}
for _, object := range list.Contents {
out <- &FileStat{
Name: strings.TrimPrefix(*object.Key, config.BucketPrefix+"/"),
Path: *object.Key,
Size: *object.Size,
ModTime: *object.LastModified,
}
}
return list.NextContinuationToken
}