forked from r0busta/go-shopify-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
62 lines (52 loc) · 1.34 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package shopify
import (
"fmt"
"net/http"
"time"
"github.com/vinhluan/go-graphql-client"
)
type Option func(shopClient *Client)
func WithGraphQLClient(gql graphql.GraphQL) Option {
return func(c *Client) {
c.gql = gql
}
}
// WithVersion optionally sets the API version if the passed string is valid.
func WithVersion(apiVersion string) Option {
return func(c *Client) {
if apiVersion != "" {
c.apiBasePath = fmt.Sprintf("%s/%s", defaultAPIBasePath, apiVersion)
}
}
}
// WithToken optionally sets access token.
func WithToken(token string) Option {
return func(c *Client) {
c.accessToken = token
}
}
// WithPrivateAppAuth optionally sets private app credentials (API key and access token).
func WithPrivateAppAuth(apiKey string, accessToken string) Option {
return func(c *Client) {
c.apiKey = apiKey
c.accessToken = accessToken
}
}
// WithRetries optionally sets maximum retry count for an API call.
func WithRetries(retries int) Option {
return func(c *Client) {
c.retries = retries
}
}
// WithTimeout optionally sets timeout for each HTTP requests made.
func WithTimeout(timeout time.Duration) Option {
return func(c *Client) {
c.timeout = timeout
}
}
// WithTransport optionally sets transport for HTTP client.
func WithTransport(transport http.RoundTripper) Option {
return func(c *Client) {
c.transport = transport
}
}