-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
178 lines (161 loc) · 3.51 KB
/
options.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
package storage
import (
"context"
"time"
)
const (
// defaultRegion custom
defaultRegion = "custom"
// defaultCallerSkip default of func caller skip
defaultCallerSkip = 1
// defaultTimeout 3 * time.Second
defaultTimeout = 3 * time.Second
// defaultListMaxKeys 默认获取所有对象
defaultListMaxKeys = -1
// defaultListRecursive 默认获取子文件夹对象
defaultListRecursive = true
// defaultPresignExpire default
defaultPresignExpire = time.Hour * 24
)
// defaultContext default context
var defaultContext = context.Background()
// Options .
type Options struct {
// Context context
Context context.Context
// Timeout 连接超时时间
Timeout time.Duration
// Region region
Region string
// SSL use ssl
UseSSL bool
}
// NewOptions .
func NewOptions(opts ...func(o *Options)) *Options {
var o = &Options{
Context: defaultContext,
Timeout: defaultTimeout,
Region: defaultRegion,
UseSSL: false,
}
for _, opt := range opts {
opt(o)
}
return o
}
// PutOptions .
type PutOptions struct {
Context context.Context
// increases the number of callers skipped by caller annotation
CallerSkip int
}
// NewPutOptions .
func NewPutOptions(opts ...func(o *PutOptions)) *PutOptions {
var o = &PutOptions{
Context: defaultContext,
CallerSkip: defaultCallerSkip,
}
for _, opt := range opts {
opt(o)
}
return o
}
// GetOptions .
type GetOptions struct {
Context context.Context
// object version
VersionID string
// increases the number of callers skipped by caller annotation
CallerSkip int
}
// NewGetOptions .
func NewGetOptions(opts ...func(o *GetOptions)) *GetOptions {
var o = &GetOptions{
Context: defaultContext,
CallerSkip: defaultCallerSkip,
}
for _, opt := range opts {
opt(o)
}
return o
}
// DelOptions .
type DelOptions struct {
Context context.Context
// object version id
VersionID string
// increases the number of callers skipped by caller annotation
CallerSkip int
}
// NewDelOptions .
func NewDelOptions(opts ...func(o *DelOptions)) *DelOptions {
var o = &DelOptions{
Context: defaultContext,
CallerSkip: defaultCallerSkip,
}
for _, opt := range opts {
opt(o)
}
return o
}
// ListOptions .
type ListOptions struct {
Context context.Context
MaxKeys int
// ignore '/' delimiter
Recursive bool
// increases the number of callers skipped by caller annotation
CallerSkip int
}
// NewListOptions .
func NewListOptions(opts ...func(o *ListOptions)) *ListOptions {
var o = &ListOptions{
Context: defaultContext,
MaxKeys: defaultListMaxKeys,
Recursive: defaultListRecursive,
CallerSkip: defaultCallerSkip,
}
for _, opt := range opts {
opt(o)
}
return o
}
// CopyOptions .
type CopyOptions struct {
Context context.Context
// increases the number of callers skipped by caller annotation
CallerSkip int
}
// NewCopyOptions .
func NewCopyOptions(opts ...func(o *CopyOptions)) *CopyOptions {
var o = &CopyOptions{
Context: defaultContext,
CallerSkip: defaultCallerSkip,
}
for _, opt := range opts {
opt(o)
}
return o
}
// PresignOptions .
type PresignOptions struct {
Context context.Context
// object version id
VersionID string
// expires time (s)
Expires time.Duration
// increases the number of callers skipped by caller annotation
CallerSkip int
}
// NewPresignOptions .
func NewPresignOptions(opts ...func(o *PresignOptions)) *PresignOptions {
var o = &PresignOptions{
Context: defaultContext,
Expires: defaultPresignExpire,
CallerSkip: defaultCallerSkip,
}
for _, opt := range opts {
opt(o)
}
return o
}