-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.go
45 lines (39 loc) · 1.06 KB
/
data.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
package sdk
import (
"io"
"path"
"github.com/clawio/clawiod/codes"
)
// DataService is the interface that specifies the methods to call a data service.
type DataService interface {
Upload(pathSpec string, r io.Reader, checksum string) (*codes.Response, error)
Download(pathSpec string) (io.Reader, *codes.Response, error)
}
type dataService struct {
client *client
baseURL string
}
func (s *dataService) Upload(pathSpec string, r io.Reader, checksum string) (*codes.Response, error) {
pathSpec = path.Join("/", pathSpec)
req, err := s.client.newUploadRequest("upload"+pathSpec, r)
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 *dataService) Download(pathSpec string) (io.Reader, *codes.Response, error) {
pathSpec = path.Join("/", pathSpec)
req, err := s.client.newRequest("GET", "download"+pathSpec, nil)
if err != nil {
return nil, nil, err
}
resp, err := s.client.do(req, nil, false)
if err != nil {
return nil, resp, err
}
return resp.Body, resp, nil
}