-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
68 lines (54 loc) · 1.51 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
package plum
import (
"log/slog"
"os"
"time"
"github.com/go-plum/plum/render"
)
type serverOptions struct {
Log Logger
MaxMultipartMemory int64
readHeaderTimeout time.Duration
HTMLRender render.HTMLRender
}
const defaultMultipartMemory = 32 << 20 // 32 MB
var defaultServerOptions = serverOptions{
Log: slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})),
MaxMultipartMemory: defaultMultipartMemory,
readHeaderTimeout: time.Second * 45,
}
// A ServerOption sets options such as credentials, codec and keepalive parameters, etc.
type ServerOption interface {
apply(*serverOptions)
}
// funcServerOption wraps a function that modifies serverOptions into an
// implementation of the ServerOption interface.
type funcServerOption struct {
f func(*serverOptions)
}
func (fdo *funcServerOption) apply(do *serverOptions) {
fdo.f(do)
}
func newFuncServerOption(f func(*serverOptions)) *funcServerOption {
return &funcServerOption{
f: f,
}
}
// ReadHeaderTimeout this is newFuncServerOption example.
func ReadHeaderTimeout(d time.Duration) ServerOption {
return newFuncServerOption(func(o *serverOptions) {
o.readHeaderTimeout = d
})
}
// HTMLRender this is newFuncServerOption example.
func HTMLRender(d render.HTMLRender) ServerOption {
return newFuncServerOption(func(o *serverOptions) {
o.HTMLRender = d
})
}
// WithLogger setting logger .
func WithLogger(log Logger) ServerOption {
return newFuncServerOption(func(o *serverOptions) {
o.Log = log
})
}