-
Notifications
You must be signed in to change notification settings - Fork 0
/
courier.go
45 lines (35 loc) · 873 Bytes
/
courier.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
package courier
import (
"github.com/DankBotList/Courier/master"
"github.com/gin-gonic/gin"
"github.com/olahol/melody"
)
// Instance an instance of a courier, locked by a file.
type Instance struct {
melody *melody.Melody
engine *gin.Engine
config Config
hub *master.Hub
InstanceID string
}
// New creates a new instance or throws errors.
func New(engine *gin.Engine) (i *Instance, err error) {
i = &Instance{
melody: melody.New(),
engine: engine,
config: Config{},
}
if err = i.config.Load(); err != nil {
return
}
i.hub = master.NewHub(i.config.AuthenticationKey)
engine.GET(i.config.WebSocketPath, func(ctx *gin.Context) {
i.hub.ServeWs(ctx.Writer, ctx.Request)
})
// TODO build stuffs
return
}
// SetInstanceID sets the instance id to be used when communicating
func (i *Instance) SetInstanceID(id string) {
i.InstanceID = id
}