-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
41 lines (33 loc) · 889 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
package pts
import "fmt"
type MessageSendFunc func(message []byte) error
type Client struct {
Id string
sendMessage MessageSendFunc
properties map[string]interface{}
}
func NewClient(sendMessage MessageSendFunc, properties map[string]interface{}) *Client {
return &Client{
Id: "",
sendMessage: sendMessage,
properties: properties,
}
}
func (client *Client) Send(message []byte) error {
return client.sendMessage(message)
}
func (client *Client) MustGet(key string) interface{} {
if value, exists := client.Get(key); exists {
return value
}
panic(fmt.Sprintf("Key '%s' does not exist", key))
}
func (client *Client) Get(key string) (value interface{}, exists bool) {
if val, ok := client.properties[key]; ok {
return val, ok
}
return nil, false
}
func (client *Client) Set(key string, value interface{}) {
client.properties[key] = value
}