-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
44 lines (36 loc) · 848 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package client
import (
"net/http"
"time"
"github.com/sirupsen/logrus"
)
// HTTPClient is a simple interface for http.Client.
// Reason: mock client in tests.
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
// Client for Advent of Code.
type Client struct {
SessionToken string
HTTPClient HTTPClient
logger *logrus.Logger
}
// RequestTimout is the timeout of a request in seconds.
const RequestTimout = 10
// NewClient creates a new client.
func NewClient(token string) Client {
return Client{
SessionToken: token,
HTTPClient: &http.Client{
Transport: nil,
CheckRedirect: nil,
Jar: nil,
Timeout: time.Second * RequestTimout,
},
logger: logrus.New(),
}
}
// LogLevel sets logger level.
func (c *Client) LogLevel(level logrus.Level) {
c.logger.SetLevel(level)
}