-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.v2.go
106 lines (92 loc) · 1.99 KB
/
option.v2.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package engineio
import (
"net/http"
"sync"
"time"
eiot "github.com/oarkflow/socketio/engineio/transport"
)
func init() {
withPath[1] = func(path string) Option {
return func(o OptionWith) {
if v, ok := o.(*serverV2); ok {
v.path = &path
}
}
}
}
func WithCodec(codec eiot.Codec) Option {
return func(o OptionWith) {
if v, ok := o.(*serverV2); ok {
v.codec = codec
}
}
}
func WithPingTimeout(d time.Duration) Option {
return func(o OptionWith) {
if v, ok := o.(*serverV2); ok {
v.pingTimeout = d
}
}
}
func WithUpgradeTimeout(d time.Duration) Option {
return func(o OptionWith) {
if v, ok := o.(*serverV2); ok {
v.upgradeTimeout = d
}
}
}
func WithCookie(name, path string, httpOnly bool) Option {
return func(o OptionWith) {
if v, ok := o.(*serverV2); ok {
v.cookie.name = name
v.cookie.path = path
v.cookie.httpOnly = httpOnly
}
}
}
func WithGenerateIDFunc(fn func() SessionID) Option {
return func(o OptionWith) {
if v, ok := o.(*serverV2); ok {
v.generateID = fn
}
}
}
func WithTransportChannelBuffer(n int) Option {
return func(o OptionWith) {
if v, ok := o.(*serverV2); ok {
v.transportChanBuf = n
}
}
}
func WithTransportOption(opts ...eiot.Option) Option {
return func(o OptionWith) {
if v, ok := o.(*serverV2); ok {
v.eto = append(v.eto, opts...)
}
}
}
var clearTransport = new(sync.Once)
func WithTransport(name eiot.Name, tr func(SessionID, eiot.Codec) eiot.Transporter) Option {
return func(o OptionWith) {
if v, ok := o.(*serverV2); ok {
clearTransport.Do(func() {
v.transports = make(map[eiot.Name]func(SessionID, eiot.Codec) eiot.Transporter)
})
v.transports[name] = tr
}
}
}
func WithInitialPackets(fn func(eiot.Transporter, *http.Request)) Option {
return func(o OptionWith) {
if v, ok := o.(*serverV2); ok {
v.initialPackets = fn
}
}
}
func WithSessionShave(d time.Duration) Option {
return func(o OptionWith) {
if v, ok := o.(*serverV2); ok {
v.sessions.(*sessions).shave = d
}
}
}