-
Notifications
You must be signed in to change notification settings - Fork 349
Expand file tree
/
Copy pathoptions.go
More file actions
86 lines (73 loc) · 2.3 KB
/
options.go
File metadata and controls
86 lines (73 loc) · 2.3 KB
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
package core
import (
"time"
"github.com/buildkite/agent/v3/logger"
)
type controllerConfig struct {
logger logger.Logger
retrySleepFunc func(time.Duration)
// Controller creation options - ignored for more specific functions.
endpoint string
userAgent string
debugHTTP bool
allowHTTP2 bool
priority string
scriptEvalEnabled bool
}
// ControllerOption is a functional option for setting optional behaviour.
type ControllerOption func(*controllerConfig)
// WithLogger enables logging through a particular logger.
// Defaults to [logger.Discard].
func WithLogger(l logger.Logger) ControllerOption {
return func(c *controllerConfig) {
c.logger = l
}
}
// WithRetrySleepFunc is used to override the inter-retry sleep in roko.
// This is mainly useful for unit tests. Defaults to nil (default sleep).
func WithRetrySleepFunc(f func(time.Duration)) ControllerOption {
return func(c *controllerConfig) {
c.retrySleepFunc = f
}
}
// WithEndpoint allows overriding the API endpoint (base URL).
// Defaults to "https://agent-edge.buildkite.com/v3".
func WithEndpoint(endpoint string) ControllerOption {
return func(c *controllerConfig) {
c.endpoint = endpoint
}
}
// WithUserAgent allows overriding the user agent.
// Defaults to the value retuned from [version.UserAgent].
func WithUserAgent(userAgent string) ControllerOption {
return func(c *controllerConfig) {
c.userAgent = userAgent
}
}
// WithDebugHTTP can be used to enable HTTP debug logs.
// Only applies to agent creation. Defaults to false.
func WithDebugHTTP(debug bool) ControllerOption {
return func(c *controllerConfig) {
c.debugHTTP = debug
}
}
// WithAllowHTTP can be used to change whether HTTP/2 is allowed.
// Only applies to agent creation. Defaults to true.
func WithAllowHTTP2(allow bool) ControllerOption {
return func(c *controllerConfig) {
c.allowHTTP2 = allow
}
}
// WithPriority sets the agent priority value. Defaults to the empty string.
func WithPriority(priority string) ControllerOption {
return func(c *controllerConfig) {
c.priority = priority
}
}
// WithScriptEvalEnabled sets the ScriptEvalEnabled registration parameter.
// Defaults to true.
func WithScriptEvalEnabled(enabled bool) ControllerOption {
return func(c *controllerConfig) {
c.scriptEvalEnabled = enabled
}
}