-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
72 lines (56 loc) · 1.21 KB
/
client.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
63
64
65
66
67
68
69
70
71
72
package eclair
import (
"net/http"
"github.com/edobtc/go-eclair/httpclient"
)
type Client struct {
settings *Settings
BaseURL string
HTTPClient *http.Client
Debug bool
}
func NewClient() *Client {
return &Client{
settings: NewDefaultSettings(),
HTTPClient: httpclient.New(),
}
}
func NewClientFromSettings(settings *Settings) *Client {
return &Client{
settings: settings,
HTTPClient: httpclient.New(),
}
}
func (c *Client) _settings() *Settings {
if c.settings == nil {
c.settings = NewDefaultSettings()
}
if c.settings.Credentials == nil {
c.settings.Credentials = &Credentials{}
}
return c.settings
}
func (c *Client) WithBaseURL(baseURL string) *Client {
c.BaseURL = baseURL
return c
}
func (c *Client) WithCredentials(creds *Credentials) *Client {
c._settings().Credentials = creds
return c
}
func (c *Client) WithUser(user string) *Client {
c._settings().Credentials.User = user
return c
}
func (c *Client) WithPassword(password string) *Client {
c.settings.Credentials.Password = password
return c
}
func (c *Client) WithHTTPClient(client *http.Client) *Client {
c.HTTPClient = client
return c
}
func (c *Client) WithDebug(debug bool) *Client {
c.Debug = debug
return c
}