-
Notifications
You must be signed in to change notification settings - Fork 15
/
options.go
56 lines (48 loc) 路 1.19 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
package adminserver
import "time"
type (
// Option captures a configurable parameter in admin HTTP server.
Option func(*options) error
options struct {
listenAddr string
readTimeout time.Duration
writeTimeout time.Duration
}
)
func newOptions(o ...Option) (*options, error) {
opts := &options{
listenAddr: "0.0.0.0:3102",
readTimeout: 30 * time.Second,
writeTimeout: 30 * time.Second,
}
for _, apply := range o {
if err := apply(opts); err != nil {
return nil, err
}
}
return opts, nil
}
// WithListenAddr sets the net address on which the admin HTTP server is exposed.
// If uset, the default address of '0.0.0.0:3102' is used.
func WithListenAddr(addr string) Option {
return func(o *options) error {
o.listenAddr = addr
return nil
}
}
// WithReadTimeout set s the HTTP read timeout.
// If unset, the default of 30 seconds is used.
func WithReadTimeout(t time.Duration) Option {
return func(o *options) error {
o.readTimeout = t
return nil
}
}
// WithWriteTimeout set s the HTTP write timeout.
// If unset, the default of 30 seconds is used.
func WithWriteTimeout(t time.Duration) Option {
return func(o *options) error {
o.writeTimeout = t
return nil
}
}