You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
624 B
Go

package client
import (
"encoding/json"
"io"
"net/http"
"net/url"
"time"
)
// Client for open hardware monitor
type Client struct {
Timeout time.Duration
URL url.URL
}
// Fetch requests
func (c *Client) Fetch() (*Node, error) {
client := http.Client{Timeout: c.Timeout}
resp, err := client.Get(c.URL.String())
if err != nil {
return nil, err
}
defer resp.Body.Close()
return c.Decode(resp.Body)
}
// Decode json
func (c *Client) Decode(r io.Reader) (*Node, error) {
node := &Node{}
decoder := json.NewDecoder(r)
if err := decoder.Decode(node); err != nil {
return nil, err
}
return node, nil
}