This repository has been archived on 2021-09-02. You can view files and clone it, but cannot push or open issues or pull requests.
my-bloody-hetzner-sb-notifier/client/client.go

30 lines
434 B
Go
Raw Normal View History

package client
import (
"encoding/json"
"net/http"
"time"
)
type Client struct {
httpClient *http.Client
}
func NewClient() *Client {
crawler := &Client{
&http.Client{Timeout: 10 * time.Second} ,
}
return crawler
}
func (c *Client) DoRequest(url string, target interface{}) error {
r, err := c.httpClient.Get(url)
if err != nil {
return err
}
defer r.Body.Close()
return json.NewDecoder(r.Body).Decode(target)
}