-
Notifications
You must be signed in to change notification settings - Fork 2
/
interfaces.go
62 lines (51 loc) · 1.38 KB
/
interfaces.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
package wasabi
import (
"context"
"net/http"
"github.com/coder/websocket"
)
type MessageType = websocket.MessageType
const (
MsgTypeText MessageType = websocket.MessageText
MsgTypeBinary MessageType = websocket.MessageBinary
)
type Request interface {
Data() []byte
RoutingKey() string
Context() context.Context
WithContext(ctx context.Context) Request
}
// Dispatcher is interface for dispatchers
type Dispatcher interface {
Dispatch(conn Connection, msgType MessageType, data []byte)
}
// OnMessage is type for OnMessage callback
type OnMessage func(conn Connection, msgType MessageType, data []byte)
// Connection is interface for connections
type Connection interface {
Send(msgType MessageType, msg []byte) error
Context() context.Context
ID() string
Close(status websocket.StatusCode, reason string, closingCtx ...context.Context) error
}
// RequestHandler is interface for request handlers
type RequestHandler interface {
Handle(conn Connection, req Request) error
}
// Channel is interface for channels
type Channel interface {
Path() string
Handler() http.Handler
Close(ctx ...context.Context) error
}
// ConnectionRegistry is interface for connection registries
type ConnectionRegistry interface {
HandleConnection(
ctx context.Context,
ws *websocket.Conn,
cb OnMessage,
)
GetConnection(id string) Connection
Close(ctx ...context.Context) error
CanAccept() bool
}