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
Mahmoud Rahbar Azad 66001f861f
Initial commit.
Example output:
Got 580 offers. Filtered offers: 3
           ID|     Ram|             HDD|                           CPU|    Price|   Score|  Reduce time|Specials
  SB57-931121|  128 GB|  2x 2 TB (4096)|  Intel Xeon E5-1650V2 (12518)|  57.00 €|  103.12|      53h 53m|ECC, Ent. HDD, iNIC
  SB69-927780|  128 GB|  2x 2 TB (4096)|  Intel Xeon E5-1650V3 (13335)|  69.00 €|   89.92|      49h 39m|ECC, Ent. HDD, iNIC
  SB76-910394|  128 GB|  3x 2 TB (6144)|  Intel Xeon E5-1650V2 (12518)|  76.00 €|   82.73|      01h 21m|ECC, Ent. HDD, iNIC
2018-10-22 23:55:29 +02:00

29 lines
434 B
Go

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)
}