mirror of
https://github.com/badkaktus/gorocket.git
synced 2025-07-13 01:10:14 +02:00
add Option
This commit is contained in:
32
gorocket.go
32
gorocket.go
@ -16,16 +16,42 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewClient creates new Facest.io client with given API key
|
// NewClient creates new Facest.io client with given API key
|
||||||
func NewClient(url string) *Client {
|
func NewClient(opts ...Option) *Client {
|
||||||
return &Client{
|
c := &Client{
|
||||||
//userID: user,
|
//userID: user,
|
||||||
HTTPClient: &http.Client{
|
HTTPClient: &http.Client{
|
||||||
Timeout: 5 * time.Minute,
|
Timeout: 5 * time.Minute,
|
||||||
},
|
},
|
||||||
//xToken: token,
|
//xToken: token,
|
||||||
baseURL: url,
|
// baseURL: url,
|
||||||
apiVersion: "api/v1",
|
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 {
|
func (c *Client) sendRequest(req *http.Request, v interface{}) error {
|
||||||
|
Reference in New Issue
Block a user