-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
45 lines (40 loc) · 1014 Bytes
/
option.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
package coincheck
import (
"fmt"
"net/http"
"net/url"
)
// Option is a parameter to be specified when creating a Coincheck
// client to configure the http client details.
type Option func(*Client) error
// WithHTTPClient sets the HTTP client which will be used to make requests.
func WithHTTPClient(client *http.Client) Option {
return func(c *Client) error {
if client == nil {
return ErrNilHTTPClient
}
c.client = client
return nil
}
}
// WithBaseURL sets the base URL for the client to make requests to.
func WithBaseURL(u string) Option {
return func(c *Client) error {
baseURL, err := url.Parse(u)
if err != nil {
return fmt.Errorf("%w: %s", ErrInvalidBaseURL, err.Error())
}
c.baseURL = baseURL
return nil
}
}
// WithCredentials sets the credentials to be used to authenticate with the Coincheck API.
func WithCredentials(key, secret string) Option {
return func(c *Client) error {
c.credentials = &credentials{
key: key,
secret: secret,
}
return nil
}
}