-
Notifications
You must be signed in to change notification settings - Fork 7
/
options.go
65 lines (55 loc) · 1.09 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
package server
import (
"context"
"sync"
)
type Options struct {
Network string
Addr string
Timeout string
ReadTimeout string
WriteTimeout string
On bool // pref switch
Once sync.Once // do once
//
//
//
Metadata map[string]string
Name string
Id string
Version string
// Other options for implementations of the interface
// can be stored in a context
Context context.Context
}
// Init initialises the default server with options passed in
func Init(opt ...Option) {
if DefaultServer == nil {
DefaultServer = newGinServer(opt...)
}
DefaultServer.Init(opt...)
}
// String returns name of Server implementation
func String() string {
return DefaultServer.String()
}
func newOptions(opt ...Option) Options {
opts := Options{
Network: "",
Addr: "",
Timeout: "",
ReadTimeout: "",
WriteTimeout: "",
On: true,
Once: sync.Once{},
Metadata: map[string]string{},
Name: "",
Id: "",
Version: "",
Context: nil,
}
for _, o := range opt {
o(&opts)
}
return opts
}