diff options
Diffstat (limited to 'vendor/github.com/hashicorp/go-getter/client_option.go')
-rw-r--r-- | vendor/github.com/hashicorp/go-getter/client_option.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-getter/client_option.go b/vendor/github.com/hashicorp/go-getter/client_option.go new file mode 100644 index 0000000..c1ee413 --- /dev/null +++ b/vendor/github.com/hashicorp/go-getter/client_option.go | |||
@@ -0,0 +1,46 @@ | |||
1 | package getter | ||
2 | |||
3 | import "context" | ||
4 | |||
5 | // A ClientOption allows to configure a client | ||
6 | type ClientOption func(*Client) error | ||
7 | |||
8 | // Configure configures a client with options. | ||
9 | func (c *Client) Configure(opts ...ClientOption) error { | ||
10 | if c.Ctx == nil { | ||
11 | c.Ctx = context.Background() | ||
12 | } | ||
13 | c.Options = opts | ||
14 | for _, opt := range opts { | ||
15 | err := opt(c) | ||
16 | if err != nil { | ||
17 | return err | ||
18 | } | ||
19 | } | ||
20 | // Default decompressor values | ||
21 | if c.Decompressors == nil { | ||
22 | c.Decompressors = Decompressors | ||
23 | } | ||
24 | // Default detector values | ||
25 | if c.Detectors == nil { | ||
26 | c.Detectors = Detectors | ||
27 | } | ||
28 | // Default getter values | ||
29 | if c.Getters == nil { | ||
30 | c.Getters = Getters | ||
31 | } | ||
32 | |||
33 | for _, getter := range c.Getters { | ||
34 | getter.SetClient(c) | ||
35 | } | ||
36 | return nil | ||
37 | } | ||
38 | |||
39 | // WithContext allows to pass a context to operation | ||
40 | // in order to be able to cancel a download in progress. | ||
41 | func WithContext(ctx context.Context) func(*Client) error { | ||
42 | return func(c *Client) error { | ||
43 | c.Ctx = ctx | ||
44 | return nil | ||
45 | } | ||
46 | } | ||