-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy_test.go
44 lines (36 loc) · 1.04 KB
/
proxy_test.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
package interruptible_websocket_proxy
import (
"go.uber.org/zap"
"golang.org/x/net/websocket"
"log"
"net/http"
"net/url"
)
func ExampleNewInterruptibleWebsocketProxyHandler() {
logger := zap.NewExample()
lgr := &exampleLogger{
logger: logger,
}
parsedURL, err := url.Parse("ws://localhost:8080")
if err != nil {
log.Printf("error parsing url for setting origin: %s", err)
return
}
memoryLimitPerConn := 5 * 1024 * 1024
// Create proxy handler instance
interruptibleWebsocketProxyHandler := NewInterruptibleWebsocketProxyHandler(websocket.Config{Origin: parsedURL}, HandlerConfig{
MaxIdleConnCount: 5,
MaxAllowedErrorCountPerConn: 100,
InterruptMemoryLimitPerConnInBytes: memoryLimitPerConn,
ClientIdExtractFunc: nil,
}, lgr)
// Register proxy handler to http server
mux := http.NewServeMux()
mux.Handle("/", interruptibleWebsocketProxyHandler)
// Start webserver
err = http.ListenAndServe(":8080", mux)
if err != nil {
lgr.Error("error starting websocket server", err)
return
}
}