-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathclient.go
More file actions
41 lines (33 loc) · 791 Bytes
/
client.go
File metadata and controls
41 lines (33 loc) · 791 Bytes
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
package main
import (
"errors"
"strings"
gin "github.com/gin-gonic/gin"
)
type Client struct {
ErrandsServer *ErrandsServer
Notifications chan *Notification
Gin *gin.Context
EventSubs []string
}
func (s *ErrandsServer) RemoveClient(c *Client) {
close(c.Notifications)
s.UnregisterClient <- c
}
func (s *ErrandsServer) NewClient(c *gin.Context) (*Client, error) {
obj := &Client{
Notifications: make(chan *Notification, 10),
ErrandsServer: s,
Gin: c,
}
events := c.DefaultQuery("events", "*")
obj.EventSubs = strings.Split(events, ",")
if len(obj.EventSubs) < 1 {
return obj, errors.New("must have at least 1 event subscription")
}
s.RegisterClient <- obj
return obj, nil
}
func (c *Client) Gone() {
c.ErrandsServer.RemoveClient(c)
}