/
server_options.go
74 lines (61 loc) · 1.59 KB
/
server_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
package engineio
import (
"github.com/googollee/go-socket.io/engineio/session"
"net/http"
"time"
"github.com/googollee/go-socket.io/engineio/transport"
"github.com/googollee/go-socket.io/engineio/transport/polling"
"github.com/googollee/go-socket.io/engineio/transport/websocket"
)
// Options is options to create a server.
type Options struct {
PingTimeout time.Duration
PingInterval time.Duration
Transports []transport.Transport
SessionIDGenerator session.IDGenerator
RequestChecker CheckerFunc
ConnInitor ConnInitorFunc
}
func (c *Options) getRequestChecker() CheckerFunc {
if c != nil && c.RequestChecker != nil {
return c.RequestChecker
}
return defaultChecker
}
func (c *Options) getConnInitor() ConnInitorFunc {
if c != nil && c.ConnInitor != nil {
return c.ConnInitor
}
return defaultInitor
}
func (c *Options) getPingTimeout() time.Duration {
if c != nil && c.PingTimeout != 0 {
return c.PingTimeout
}
return time.Minute
}
func (c *Options) getPingInterval() time.Duration {
if c != nil && c.PingInterval != 0 {
return c.PingInterval
}
return time.Second * 20
}
func (c *Options) getTransport() []transport.Transport {
if c != nil && len(c.Transports) != 0 {
return c.Transports
}
return []transport.Transport{
polling.Default,
websocket.Default,
}
}
func (c *Options) getSessionIDGenerator() session.IDGenerator {
if c != nil && c.SessionIDGenerator != nil {
return c.SessionIDGenerator
}
return &session.DefaultIDGenerator{}
}
func defaultChecker(*http.Request) (http.Header, error) {
return nil, nil
}
func defaultInitor(*http.Request, Conn) {}