-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
57 lines (48 loc) · 1.39 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
package mazzaroth
import (
"net/http"
"time"
)
// mazzarothOptions config options for client
type mazzarothClientOptions struct {
httpClient *http.Client
address string
}
// Options interface for applying service options
type Options interface {
apply(*mazzarothClientOptions)
}
// funcMazzarothClientOption wraps a function that modifies Options into an
// implementation of the Option interface.
type funcMazzarothClientOption struct {
f func(*mazzarothClientOptions)
}
func (fmso *funcMazzarothClientOption) apply(opt *mazzarothClientOptions) {
fmso.f(opt)
}
func newFuncPacketOption(f func(*mazzarothClientOptions)) *funcMazzarothClientOption {
return &funcMazzarothClientOption{
f: f,
}
}
// WithHttpClient used to set the http client that the mazzaroth client should use
func WithHttpClient(client *http.Client) Options {
return newFuncPacketOption(func(o *mazzarothClientOptions) {
o.httpClient = client
})
}
// WithAddress used to set the http client that the mazzaroth client should use
func WithAddress(address string) Options {
return newFuncPacketOption(func(o *mazzarothClientOptions) {
o.address = address
})
}
// defaultOption defines a set of default options for the mazzaroth client
func defaultOption() *mazzarothClientOptions {
return &mazzarothClientOptions{
httpClient: &http.Client{
Timeout: 500 * time.Millisecond,
},
address: "http://localhost:6299",
}
}