-
Notifications
You must be signed in to change notification settings - Fork 0
/
pairs.go
190 lines (171 loc) · 4.17 KB
/
pairs.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package definitions
import (
"sort"
)
type Pair struct {
Name string
Type Type
Defaultable bool
Description string
// Only infos that declared inside definitions can set global as true.
global bool
}
func (p Pair) Global() bool {
return p.global
}
var PairMap = make(map[string]Pair)
var PairArray = []Pair{
PairContentDisposition,
PairContentMD5,
PairContentType,
PairContinuationToken,
PairCredential,
PairEndpoint,
PairListMode,
PairLocation,
PairName,
PairObjectMode,
PairOffset,
PairSize,
PairMultipartID,
PairIoCallback,
PairWorkDir,
}
func SortPairs(ps []Pair) []Pair {
sort.SliceStable(ps, func(i, j int) bool {
return ps[i].Name < ps[j].Name
})
return ps
}
var PairContentDisposition = Pair{
Name: "content_disposition",
Type: Type{Name: "string"},
global: true,
}
var PairContentMD5 = Pair{
Name: "content_md5",
Type: Type{Name: "string"},
global: true,
}
var PairContentType = Pair{
Name: "content_type",
Type: Type{Name: "string"},
Defaultable: true,
global: true,
}
var PairContinuationToken = Pair{
Name: "continuation_token",
Type: Type{Name: "string"},
Description: "specify the continuation token for list",
global: true,
}
var PairCredential = Pair{
Name: "credential",
Type: Type{Name: "string"},
global: true,
Description: "specify how to provide credential for service or storage",
}
var PairEndpoint = Pair{
Name: "endpoint",
Type: Type{Name: "string"},
global: true,
Description: "specify how to provide endpoint for service or storage",
}
var PairListMode = Pair{
Name: "list_mode",
Type: Type{Package: "types", Name: "ListMode"},
global: true,
}
var PairLocation = Pair{
Name: "location",
Type: Type{Name: "string"},
global: true,
Description: "specify the location for service or storage",
}
var PairName = Pair{
Name: "name",
Type: Type{Name: "string"},
global: true,
Description: "specify the storage name",
}
var PairObjectMode = Pair{
Name: "object_mode",
Type: Type{Package: "types", Name: "ObjectMode"},
global: true,
Description: `ObjectMode hint`,
}
var PairOffset = Pair{
Name: "offset",
Type: Type{Name: "int64"},
global: true,
Description: `specify offset for this request, storage will seek to this offset before read`,
}
var PairSize = Pair{
Name: "size",
Type: Type{Name: "int64"},
global: true,
Description: `specify size for this request, storage will only read limited content data`,
}
var PairMultipartID = Pair{
Name: "multipart_id",
Type: Type{Name: "string"},
global: true,
}
var PairIoCallback = Pair{
Name: "io_callback",
Type: Type{Name: "func([]byte)"},
Defaultable: true,
global: true,
Description: `specify what todo every time we read data from source`,
}
var PairWorkDir = Pair{
Name: "work_dir",
Type: Type{Name: "string"},
global: true,
Description: `specify the work dir for service or storage, every operation will be relative to this dir.
work_dir SHOULD be an absolute path.
work_dir will be default to / if not set.
work_dir SHOULD be Unix style for object storage services.
For fs storage service on windows platform, the behavior is defined separately.`,
}
func init() {
// Normalize default pairs.
dps := make([]Pair, 0)
for _, v := range PairArray {
if !v.Defaultable {
continue
}
dps = append(dps, Pair{
Name: "default_" + v.Name,
Type: v.Type,
Description: "default value for " + v.Name,
global: true,
})
}
PairArray = append(PairArray, dps...)
// Build feature pairs.
fps := make([]Pair, 0)
m := make(map[string]bool)
for _, fes := range [][]Feature{FeaturesService, FeaturesStorage} {
for _, f := range fes {
if f.Type != FeatureTypeVirtual {
continue
}
if m[f.Name] {
continue
}
m[f.Name] = true
fps = append(fps, Pair{
Name: "enable_" + f.Name,
Type: Type{Name: "bool"},
Description: "Enable feature " + f.Name,
global: true,
})
}
}
PairArray = append(PairArray, fps...)
// Setup maps.
for _, v := range PairArray {
PairMap[v.Name] = v
}
}