-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathgcs.go
50 lines (42 loc) · 933 Bytes
/
gcs.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 (
"context"
"cloud.google.com/go/storage"
"google.golang.org/api/iterator"
)
type gcsProvider struct {
bucket string
prefix string
baseURL string
client *storage.Client
ctx context.Context
b *storage.BucketHandle
}
// List returns the files in an gcs bucket.
func (c *gcsProvider) List(prefix, delimiter, marker string, max int, q *storage.Query) (files []object, err error) {
resp := c.b.Objects(c.ctx, q)
// append to files
for {
f, err := resp.Next()
if err == iterator.Done {
break
}
if err != nil {
return nil, err
}
files = append(files, object{
Name: f.Name,
Size: f.Size,
BaseURL: c.BaseURL(),
})
}
return files, nil
}
// Prefix returns the prefix in an gcs bucket.
func (c *gcsProvider) Prefix() string {
return c.prefix
}
// BaseURL returns the baseURL in an gcs bucket.
func (c *gcsProvider) BaseURL() string {
return c.baseURL
}