-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
93 lines (80 loc) · 2.24 KB
/
option.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
package curling
const (
lineContinuationDefault = "\\"
lineContinuationWindows = "^"
lineContinuationPowerShell = "`"
)
type Option func(curling *Command)
// WithFollowRedirects enables the option -L, --location.
func WithFollowRedirects() Option {
return func(curling *Command) {
curling.location = true
}
}
// WithCompression enables the option --compressed.
func WithCompression() Option {
return func(curling *Command) {
curling.compressed = true
}
}
// WithInsecure enables the option -k, --insecure.
func WithInsecure() Option {
return func(curling *Command) {
curling.insecure = true
}
}
// WithLongForm enables the long form for cURL options.
// Example: --header instead of -H.
func WithLongForm() Option {
return func(curling *Command) {
curling.useLongForm = true
}
}
// WithSilent enables the option -s, --silent.
func WithSilent() Option {
return func(curling *Command) {
curling.silent = true
}
}
// WithMultiLine splits the command across multiple lines.
// The default line continuation character is backslash.
func WithMultiLine() Option {
return func(curling *Command) {
curling.useMultiLine = true
curling.lineContinuation = lineContinuationDefault
}
}
// WithWindowsMultiLine splits the command across multiple lines.
// The line continuation character is caret.
func WithWindowsMultiLine() Option {
return func(curling *Command) {
curling.useMultiLine = true
curling.lineContinuation = lineContinuationWindows
}
}
// WithPowerShellMultiLine splits the command across multiple lines.
// The line continuation character is backtick.
func WithPowerShellMultiLine() Option {
return func(curling *Command) {
curling.useMultiLine = true
curling.lineContinuation = lineContinuationPowerShell
}
}
// WithDoubleQuotes enables escaping using double quotes.
func WithDoubleQuotes() Option {
return func(curling *Command) {
curling.useDoubleQuotes = true
}
}
// WithRequestTimeout enables the option -m, --max-time.
// It sets the number of seconds the request should wait
// for a response before timing out.
// Negative value seconds will be silently ignored.
func WithRequestTimeout(seconds int) Option {
return func(curling *Command) {
if seconds < 0 {
seconds = 0
}
curling.requestTimeout = seconds
}
}