-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetadata.go
94 lines (84 loc) · 2.63 KB
/
metadata.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package sdk
import (
"path"
"github.com/clawio/clawiod/codes"
"github.com/clawio/clawiod/entities"
)
// MetaDataService is the interface that specifies the methods to call a metaData service.
type MetaDataService interface {
Init() (*codes.Response, error)
CreateTree(pathSpec string) (*codes.Response, error)
ExamineObject(pathSpec string) (*entities.ObjectInfo, *codes.Response, error)
ListTree(pathSpec string) ([]*entities.ObjectInfo, *codes.Response, error)
DeleteObject(pathSpec string) (*codes.Response, error)
MoveObject(sourcePathSpec, targetPathSpec string) (*codes.Response, error)
}
type metaDataService struct {
client *client
baseURL string
}
func (s *metaDataService) Init() (*codes.Response, error) {
req, err := s.client.newRequest("POST", "init", nil)
if err != nil {
return nil, err
}
resp, err := s.client.do(req, nil, true)
if err != nil {
return resp, err
}
return resp, nil
}
func (s *metaDataService) ExamineObject(pathSpec string) (*entities.ObjectInfo, *codes.Response, error) {
pathSpec = path.Join("/", pathSpec)
req, err := s.client.newRequest("GET", "examine"+pathSpec, nil)
if err != nil {
return nil, nil, err
}
o := &entities.ObjectInfo{}
resp, err := s.client.do(req, o, true)
if err != nil {
return o, resp, err
}
return o, resp, nil
}
func (s *metaDataService) ListTree(pathSpec string) ([]*entities.ObjectInfo, *codes.Response, error) {
pathSpec = path.Join("/", pathSpec)
req, err := s.client.newRequest("GET", "list"+pathSpec, nil)
if err != nil {
return nil, nil, err
}
var oinfos []*entities.ObjectInfo
resp, err := s.client.do(req, &oinfos, true)
if err != nil {
return nil, resp, err
}
return oinfos, resp, nil
}
func (s *metaDataService) DeleteObject(pathSpec string) (*codes.Response, error) {
pathSpec = path.Join("/", pathSpec)
req, err := s.client.newRequest("DELETE", "delete"+pathSpec, nil)
if err != nil {
return nil, err
}
return s.client.do(req, nil, true)
}
func (s *metaDataService) CreateTree(pathSpec string) (*codes.Response, error) {
pathSpec = path.Join("/", pathSpec)
req, err := s.client.newRequest("POST", "createtree"+pathSpec, nil)
if err != nil {
return nil, err
}
return s.client.do(req, nil, true)
}
func (s *metaDataService) MoveObject(sourcePathSpec, targetPathSpec string) (*codes.Response, error) {
sourcePathSpec = path.Join("/", sourcePathSpec)
targetPathSpec = path.Join("/", targetPathSpec)
req, err := s.client.newRequest("POST", "move"+sourcePathSpec, nil)
if err != nil {
return nil, err
}
values := req.URL.Query()
values.Set("target", targetPathSpec)
req.URL.RawQuery = values.Encode()
return s.client.do(req, nil, true)
}