-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
44 lines (38 loc) · 880 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
41
42
43
44
package goshopee
import (
"fmt"
"net/http"
"net/url"
)
// 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 {
pathPrefix = fmt.Sprintf("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
}
}
func WithProxy(proxyHost string) Option {
return func(c *Client) {
proxyURL, err := url.Parse(proxyHost)
if err != nil {
return
}
c.Client.Transport = &http.Transport{Proxy: http.ProxyURL(proxyURL)}
}
}