forked from OneOfOne/gserv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
80 lines (67 loc) · 1.77 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package gserv
import (
"log"
"time"
"github.com/alpineiq/gserv/router"
)
// Options allows finer control over the gserv
type Options struct {
Logger *log.Logger
RouterOptions *router.Options
ReadTimeout time.Duration
WriteTimeout time.Duration
MaxHeaderBytes int
CatchPanics bool
EnableDefaultHTTPLogging bool // disables the spam on disconnects and tls, it can hide important messages sometimes
}
// Option is a func to set internal server Options.
type Option = func(opt *Options)
// ReadTimeout sets the read timeout on the server.
// see http.Server.ReadTimeout
func ReadTimeout(v time.Duration) Option {
return func(opt *Options) {
opt.ReadTimeout = v
}
}
// WriteTimeout sets the write timeout on the server.
// see http.Server.WriteTimeout
func WriteTimeout(v time.Duration) Option {
return func(opt *Options) {
opt.WriteTimeout = v
}
}
// MaxHeaderBytes sets the max size of headers on the server.
// see http.Server.MaxHeaderBytes
func MaxHeaderBytes(v int) Option {
return func(opt *Options) {
opt.MaxHeaderBytes = v
}
}
// SetErrLogger sets the error logger on the server.
func SetErrLogger(v *log.Logger) Option {
return func(opt *Options) {
opt.Logger = v
}
}
// SetRouterOptions sets gserv/router.Options on the server.
func SetRouterOptions(v *router.Options) Option {
return func(opt *Options) {
opt.RouterOptions = v
}
}
// SetNoCatchPanics toggles catching panics in handlers.
func SetCatchPanics(enable bool) Option {
return func(opt *Options) {
opt.CatchPanics = enable
}
}
func SetProfileLabels(enable bool) Option {
return func(opt *Options) {
opt.RouterOptions.ProfileLabels = enable
}
}
func SetOnReqDone(fn router.OnRequestDone) Option {
return func(opt *Options) {
opt.RouterOptions.OnRequestDone = fn
}
}