forked from s-norris/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
40 lines (34 loc) · 896 Bytes
/
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
package goshopify
import (
"fmt"
"net/http"
)
// Option is used to configure client with options
type Option func(c *Client)
// WithVersion optionally sets the api-version if the passed string is valid
func WithVersion(apiVersion string) Option {
return func(c *Client) {
pathPrefix := defaultApiPathPrefix
if len(apiVersion) > 0 && (apiVersionRegex.MatchString(apiVersion) || apiVersion == UnstableApiVersion) {
pathPrefix = fmt.Sprintf("admin/api/%s", apiVersion)
}
c.apiVersion = apiVersion
c.pathPrefix = pathPrefix
}
}
func WithRetry(retries int) Option {
return func(c *Client) {
c.retries = retries
}
}
func WithLogger(logger LeveledLoggerInterface) Option {
return func(c *Client) {
c.log = logger
}
}
// WithHTTPClient is used to set a custom http client
func WithHTTPClient(client *http.Client) Option {
return func(c *Client) {
c.Client = client
}
}