-
Notifications
You must be signed in to change notification settings - Fork 4
/
types.go
102 lines (88 loc) · 2.43 KB
/
types.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
95
96
97
98
99
100
101
102
package wfs
import (
"io"
"os"
)
// File stores info about single file
type File struct {
Name string `json:"value"`
ID string `json:"id"`
Size int64 `json:"size"`
Date int64 `json:"date"`
Type string `json:"type"`
Files []File `json:"data,omitempty"`
}
// File stores info about single file
type Drive interface {
List(id string, config ...*ListConfig) ([]File, error)
Search(id, search string, config ...*ListConfig) ([]File, error)
Remove(id string) error
Read(id string) (io.ReadSeeker, error)
Write(id string, data io.Reader) error
Exists(id string) bool
Info(id string) (File, error)
Make(id, name string, isFolder bool) (string, error)
Copy(source, target, name string) (string, error)
Move(source, target, name string) (string, error)
Stats() (uint64, uint64, error)
}
type FileInfo interface {
os.FileInfo
File() FileID
}
type Adapter interface {
// implements Policy
Comply(FileID,int) bool
// converts client id <-> server id
ToFileID(id string) FileID
GetParent(f FileID) FileID
// file operations
List(id FileID) ([]FileInfo, error)
Search(id FileID, search string) ([]FileInfo, error)
Remove(id FileID) error
Read(id FileID) (io.ReadSeeker, error)
Write(id FileID, data io.Reader) error
Make(id FileID, name string, isFolder bool) (FileID, error)
Copy(source, target FileID, name string, isFolder bool) (FileID, error)
Move(source, target FileID, name string, isFolder bool) (FileID, error)
Info(id FileID) (FileInfo, error)
Exists(id FileID, name string) bool
Stats() (uint64, uint64, error)
}
type FileID interface {
GetPath() string
ClientID() string
IsFolder() bool
Contains(FileID) bool
}
// ListConfig contains file listing options
type ListConfig struct {
SkipFiles bool
SubFolders bool
Nested bool
Exclude MatcherFunc
Include MatcherFunc
}
// DriveConfig contains drive configuration
type DriveConfig struct {
Verbose bool
List *ListConfig
Operation *OperationConfig
Policy *Policy
}
// OperationConfig contains file operation options
type OperationConfig struct {
PreventNameCollision bool
}
// MatcherFunc receives path and returns true if path matches the rule
type MatcherFunc func(string) bool
// Supported operation modes
const (
ReadOperation int = iota
WriteOperation
)
// Policy is a rule which allows or denies operation
type Policy interface {
// Comply method returns true is operation for the path is allowed
Comply(FileID, int) bool
}