forked from bold-commerce/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
42 lines (36 loc) · 1.06 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
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
}
}
// WithRetry sets the number of times a request will be retried if a rate limit or service unavailable error is returned.
// Rate limiting can be either REST API limits or GraphQL Cost limits
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
}
}