forked from alexandrevicenzi/go-sse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
46 lines (38 loc) · 902 Bytes
/
client.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
package sse
import "log"
// Client represents a web browser connection.
type Client struct {
lastEventID,
name string
channel string
send chan *Message
}
func newClient(lastEventID, name string, channel string) *Client {
return &Client{
lastEventID,
name,
channel,
make(chan *Message),
}
}
// SendMessage sends a message to client.
func (c *Client) SendMessage(message *Message) {
c.lastEventID = message.id
c.send <- message
}
// Disconnect disconnects client.
func (c *Client) Disconnect() {
log.Println("sse.Client.Disconnect: not implemented")
}
// Name returns client's name.
func (c *Client) Name() string {
return c.name
}
// Channel returns the channel where this client is subscribed to.
func (c *Client) Channel() string {
return c.channel
}
// LastEventID returns the ID of the last message sent.
func (c *Client) LastEventID() string {
return c.lastEventID
}