1
0
mirror of https://github.com/badkaktus/gorocket.git synced 2025-03-03 14:52:40 +02:00

add Option

This commit is contained in:
Алексей Волегов 2022-09-19 14:41:05 +03:00
parent 8cc2f17225
commit 08c7076e6b

View File

@ -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 {