/
options.go
103 lines (86 loc) · 1.99 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
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
package fasthttp
import (
"github.com/clubpay/ronykit/kit"
"github.com/clubpay/ronykit/std/gateways/fasthttp/proxy"
)
type Option func(b *bundle)
func SuperFast() Option {
return func(b *bundle) {
b.utils = speedUtil()
}
}
func WithServerName(name string) Option {
return func(b *bundle) {
b.srv.Name = name
}
}
func WithBufferSize(read, write int) Option {
return func(b *bundle) {
b.srv.ReadBufferSize = read
b.srv.WriteBufferSize = write
}
}
func WithLogger(l kit.Logger) Option {
return func(b *bundle) {
b.l = l
}
}
func Listen(addr string) Option {
return func(b *bundle) {
b.listen = addr
}
}
func WithCORS(cfg CORSConfig) Option {
return func(b *bundle) {
b.cors = newCORS(cfg)
b.wsUpgrade.CheckOrigin = b.cors.handleWS
}
}
func WithPredicateKey(key string) Option {
return func(b *bundle) {
b.predicateKey = key
}
}
func WithWebsocketEndpoint(endpoint string) Option {
return func(b *bundle) {
b.wsEndpoint = endpoint
}
}
func WithReverseProxy(path string, opt ...proxy.Option) Option {
return func(b *bundle) {
var err error
b.reverseProxy, err = proxy.NewReverseProxyWith(opt...)
if err != nil {
panic(err)
}
if path == "" {
path = "/"
}
b.reverseProxyPath = path
}
}
func WithCustomRPC(in kit.IncomingRPCFactory, out kit.OutgoingRPCFactory) Option {
return func(b *bundle) {
b.rpcInFactory = in
b.rpcOutFactory = out
}
}
func WithDisableHeaderNamesNormalizing() Option {
return func(b *bundle) {
b.srv.DisableHeaderNamesNormalizing = true
}
}
// CompressionLevel is numeric representation of compression level
type CompressionLevel int
// Represents compression level that will be used in the middleware
const (
CompressionLevelDisabled CompressionLevel = -1
CompressionLevelDefault CompressionLevel = 0
CompressionLevelBestSpeed CompressionLevel = 1
CompressionLevelBestCompression CompressionLevel = 2
)
func WithCompressionLevel(level CompressionLevel) Option {
return func(b *bundle) {
b.compress = level
}
}