-
Notifications
You must be signed in to change notification settings - Fork 4
/
fs.go
77 lines (58 loc) · 1.58 KB
/
fs.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
package coreclient
import (
"encoding/json"
"io"
"net/url"
"path/filepath"
"github.com/datarhei/core-client-go/v16/api"
)
const (
SORT_DEFAULT = "none"
SORT_NONE = "none"
SORT_NAME = "name"
SORT_SIZE = "size"
SORT_LASTMOD = "lastmod"
ORDER_DEFAULT = "asc"
ORDER_ASC = "asc"
ORDER_DESC = "desc"
)
func (r *restclient) FilesystemList(name, pattern, sort, order string) ([]api.FileInfo, error) {
var files []api.FileInfo
values := url.Values{}
values.Set("glob", pattern)
values.Set("sort", sort)
values.Set("order", order)
data, err := r.call("GET", "/v3/fs/"+url.PathEscape(name)+"?"+values.Encode(), "", nil)
if err != nil {
return files, err
}
err = json.Unmarshal(data, &files)
return files, err
}
func (r *restclient) FilesystemHasFile(name, path string) bool {
if !filepath.IsAbs(path) {
path = "/" + path
}
_, err := r.call("HEAD", "/v3/fs/"+url.PathEscape(name)+path, "", nil)
return err == nil
}
func (r *restclient) FilesystemGetFile(name, path string) (io.ReadCloser, error) {
if !filepath.IsAbs(path) {
path = "/" + path
}
return r.stream("GET", "/v3/fs/"+url.PathEscape(name)+path, "", nil)
}
func (r *restclient) FilesystemDeleteFile(name, path string) error {
if !filepath.IsAbs(path) {
path = "/" + path
}
_, err := r.call("DELETE", "/v3/fs/"+url.PathEscape(name)+path, "", nil)
return err
}
func (r *restclient) FilesystemAddFile(name, path string, data io.Reader) error {
if !filepath.IsAbs(path) {
path = "/" + path
}
_, err := r.call("PUT", "/v3/fs/"+url.PathEscape(name)+path, "application/data", data)
return err
}