-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoptions.go
61 lines (50 loc) · 1.13 KB
/
options.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package api2
import (
"log"
"net/http"
)
type HttpClient interface {
Do(req *http.Request) (*http.Response, error)
CloseIdleConnections()
}
type Config struct {
errorf func(format string, args ...interface{})
authorization string // Affects only clients.
client HttpClient
maxBody int64
human bool
}
const defaultMaxBody = 10 * 1024 * 1024
func NewDefaultConfig() *Config {
return &Config{
errorf: log.Printf,
maxBody: defaultMaxBody,
}
}
type Option func(*Config)
func ErrorLogger(logger func(format string, args ...interface{})) Option {
return func(config *Config) {
config.errorf = logger
}
}
func AuthorizationHeader(authorization string) Option {
return func(config *Config) {
config.authorization = authorization
}
}
func CustomClient(client HttpClient) Option {
return func(config *Config) {
config.client = client
}
}
func MaxBody(maxBody int64) Option {
return func(config *Config) {
config.maxBody = maxBody
}
}
// Always produce pretty formatted JSON on both client and server.
func HumanJSON(enabled bool) Option {
return func(config *Config) {
config.human = enabled
}
}