-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsource.go
61 lines (50 loc) · 1.18 KB
/
source.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
53
54
55
56
57
58
59
60
61
package gcs
import (
"context"
"path"
"cloud.google.com/go/storage"
"github.com/sirupsen/logrus"
"google.golang.org/api/iterator"
"github.com/yunify/qscamel/constants"
"github.com/yunify/qscamel/model"
"github.com/yunify/qscamel/utils"
)
// List implement source.List
func (c *Client) List(ctx context.Context, j *model.DirectoryObject, fn func(o model.Object)) (err error) {
cp := path.Join(c.Path, j.Key) + "/"
it := c.client.Objects(ctx, &storage.Query{
Delimiter: "/",
Prefix: cp,
})
for {
next, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
logrus.Errorf("List objects failed for %v.", err)
return err
}
if next.Prefix != "" {
object := &model.DirectoryObject{
Key: utils.Relative(next.Prefix, c.Path),
}
fn(object)
continue
}
object := &model.SingleObject{
Key: utils.Relative(next.Name, c.Path),
Size: next.Size,
}
fn(object)
}
return
}
// Reach implement source.Fetch
func (c *Client) Reach(ctx context.Context, p string) (url string, err error) {
return "", constants.ErrEndpointFuncNotImplemented
}
// Reachable implement source.Reachable
func (c *Client) Reachable() bool {
return false
}