/
option.go
63 lines (52 loc) · 1.23 KB
/
option.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
62
63
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.
package http
import (
"net/http"
"time"
)
type options struct {
gracePeriod time.Duration
listen string
tlsConfigPath string
mux *http.ServeMux
enableH2C bool
}
// Option overrides behavior of Server.
type Option interface {
apply(*options)
}
type optionFunc func(*options)
func (f optionFunc) apply(o *options) {
f(o)
}
// WithGracePeriod sets shutdown grace period for HTTP server.
// Server waits connections to drain for specified amount of time.
func WithGracePeriod(t time.Duration) Option {
return optionFunc(func(o *options) {
o.gracePeriod = t
})
}
// WithListen sets address to listen for HTTP server.
// Server accepts incoming TCP connections on given address.
func WithListen(s string) Option {
return optionFunc(func(o *options) {
o.listen = s
})
}
func WithTLSConfig(tls string) Option {
return optionFunc(func(o *options) {
o.tlsConfigPath = tls
})
}
func WithEnableH2C(enableH2C bool) Option {
return optionFunc(func(o *options) {
o.enableH2C = enableH2C
})
}
// WithMux overrides the server's default mux.
func WithMux(mux *http.ServeMux) Option {
return optionFunc(func(o *options) {
o.mux = mux
})
}