-
Notifications
You must be signed in to change notification settings - Fork 0
/
messageClientOptions.go
66 lines (52 loc) · 1.71 KB
/
messageClientOptions.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
package websocket
import (
"time"
"github.com/fasthttp/websocket"
"github.com/valyala/fasthttp"
)
var _ MessageClientOption = MessageClientOptionFunc(nil)
type MessageClientOptionFunc func(*websocket.FastHTTPUpgrader)
func (f MessageClientOptionFunc) apply(u *websocket.FastHTTPUpgrader) {
f(u)
}
// -----------------------------------------------
func WithHandshakeTimeout(timeout time.Duration) MessageClientOption {
return MessageClientOptionFunc(func(u *websocket.FastHTTPUpgrader) {
u.HandshakeTimeout = timeout
})
}
func WithReadBufferSize(size int) MessageClientOption {
return MessageClientOptionFunc(func(u *websocket.FastHTTPUpgrader) {
u.ReadBufferSize = size
})
}
func WithWriteBufferSize(size int) MessageClientOption {
return MessageClientOptionFunc(func(u *websocket.FastHTTPUpgrader) {
u.WriteBufferSize = size
})
}
func WithWriteBufferPool(pool websocket.BufferPool) MessageClientOption {
return MessageClientOptionFunc(func(u *websocket.FastHTTPUpgrader) {
u.WriteBufferPool = pool
})
}
func WithSubprotocols(v []string) MessageClientOption {
return MessageClientOptionFunc(func(u *websocket.FastHTTPUpgrader) {
u.Subprotocols = v
})
}
func WithError(action func(ctx *fasthttp.RequestCtx, status int, reason error)) MessageClientOption {
return MessageClientOptionFunc(func(u *websocket.FastHTTPUpgrader) {
u.Error = action
})
}
func WithCheckOrigin(predicate func(ctx *fasthttp.RequestCtx) bool) MessageClientOption {
return MessageClientOptionFunc(func(u *websocket.FastHTTPUpgrader) {
u.CheckOrigin = predicate
})
}
func WithEnableCompression(enabled bool) MessageClientOption {
return MessageClientOptionFunc(func(u *websocket.FastHTTPUpgrader) {
u.EnableCompression = enabled
})
}