fixed linter errors
This commit is contained in:
parent
a3cd1aec64
commit
7f46529352
@ -9,21 +9,29 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// ClientResponse is a key value mapping
|
||||
type ClientResponse map[string]interface{}
|
||||
|
||||
// A Client uses the http client to talk
|
||||
// to the birdwatcher API.
|
||||
type Client struct {
|
||||
Api string
|
||||
api string
|
||||
}
|
||||
|
||||
// NewClient creates a new client instance
|
||||
func NewClient(api string) *Client {
|
||||
client := &Client{
|
||||
Api: api,
|
||||
api: api,
|
||||
}
|
||||
return client
|
||||
}
|
||||
|
||||
// Make API request, parse response and return map or error
|
||||
func (self *Client) Get(client *http.Client, url string) (ClientResponse, error) {
|
||||
// Get makes an API request.
|
||||
// Parse response and return map or error.
|
||||
func (c *Client) Get(
|
||||
client *http.Client,
|
||||
url string,
|
||||
) (ClientResponse, error) {
|
||||
res, err := client.Get(url)
|
||||
if err != nil {
|
||||
return ClientResponse{}, err
|
||||
@ -46,18 +54,26 @@ func (self *Client) Get(client *http.Client, url string) (ClientResponse, error)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Make API request, parse response and return map or error
|
||||
func (self *Client) GetJson(endpoint string) (ClientResponse, error) {
|
||||
// GetJSON makes an API request.
|
||||
// Parse JSON response and return map or error.
|
||||
func (c *Client) GetJSON(
|
||||
endpoint string,
|
||||
) (ClientResponse, error) {
|
||||
client := &http.Client{}
|
||||
|
||||
return self.Get(client, self.Api+endpoint)
|
||||
return c.Get(client, c.api+endpoint)
|
||||
}
|
||||
|
||||
// Make API request, parse response and return map or error
|
||||
func (self *Client) GetJsonTimeout(timeout time.Duration, endpoint string) (ClientResponse, error) {
|
||||
// GetJSONTimeout make an API request, parses the
|
||||
// JSON response and returns the result or an error.
|
||||
//
|
||||
// This will all go away one we use the new context.
|
||||
func (c *Client) GetJSONTimeout(
|
||||
timeout time.Duration,
|
||||
endpoint string,
|
||||
) (ClientResponse, error) {
|
||||
client := &http.Client{
|
||||
Timeout: timeout,
|
||||
}
|
||||
|
||||
return self.Get(client, self.Api+endpoint)
|
||||
return c.Get(client, c.api+endpoint)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user