-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
70 lines (60 loc) · 1.18 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
64
65
66
67
68
69
70
package revproxy
import (
"time"
)
type serverOptFunc func(*serverOpt)
type serverOpt struct {
listenAddr string
allowHeaders []string
rto time.Duration
wto time.Duration
ito time.Duration
rhto time.Duration
}
func ListenAddr(addr string) serverOptFunc {
return func(opt *serverOpt) {
opt.listenAddr = addr
}
}
func AllowHeaders(headers []string) serverOptFunc {
return func(opt *serverOpt) {
opt.allowHeaders = headers
}
}
func ReadTimeout(dur time.Duration) serverOptFunc {
return func(opt *serverOpt) {
opt.rto = dur
}
}
func WriteTimeout(dur time.Duration) serverOptFunc {
return func(opt *serverOpt) {
opt.wto = dur
}
}
func IdleTimeout(dur time.Duration) serverOptFunc {
return func(opt *serverOpt) {
opt.ito = dur
}
}
func ReadHeaderTimeout(dur time.Duration) serverOptFunc {
return func(opt *serverOpt) {
opt.rhto = dur
}
}
func initOpt(opt *serverOpt) {
if len(opt.listenAddr) < 1 {
opt.listenAddr = "[0.0.0.0]:8080"
}
if opt.rto < 1 {
opt.rto = 60 * time.Second
}
if opt.wto < 1 {
opt.wto = 60 * time.Second
}
if opt.ito < 1 {
opt.wto = 60 * time.Second
}
if opt.rhto < 1 {
opt.wto = 10 * time.Second
}
}