mirror of
https://github.com/badkaktus/gorocket.git
synced 2025-03-03 14:52:40 +02:00
add Option
This commit is contained in:
parent
8cc2f17225
commit
08c7076e6b
32
gorocket.go
32
gorocket.go
@ -16,16 +16,42 @@ type Client struct {
|
||||
}
|
||||
|
||||
// NewClient creates new Facest.io client with given API key
|
||||
func NewClient(url string) *Client {
|
||||
return &Client{
|
||||
func NewClient(opts ...Option) *Client {
|
||||
c := &Client{
|
||||
//userID: user,
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: 5 * time.Minute,
|
||||
},
|
||||
//xToken: token,
|
||||
baseURL: url,
|
||||
// baseURL: url,
|
||||
apiVersion: "api/v1",
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
o(c)
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
type Option func(*Client)
|
||||
|
||||
func WithUrl(url string) Option {
|
||||
return func(c *Client) {
|
||||
c.baseURL = url
|
||||
}
|
||||
}
|
||||
|
||||
func WithUserID(userID string) Option {
|
||||
return func(c *Client) {
|
||||
c.userID = userID
|
||||
}
|
||||
}
|
||||
|
||||
func WithXToken(xtoken string) Option {
|
||||
return func(c *Client) {
|
||||
c.xToken = xtoken
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) sendRequest(req *http.Request, v interface{}) error {
|
||||
|
Loading…
x
Reference in New Issue
Block a user