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 }