-
Notifications
You must be signed in to change notification settings - Fork 35
/
hal.go
54 lines (45 loc) · 1.23 KB
/
hal.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
package hal
// Handler constants
const (
HEAR = "HEAR"
RESPOND = "RESPOND"
TOPIC = "TOPIC"
ENTER = "ENTER"
LEAVE = "LEAVE"
)
var (
// Config is a global config
Config = newConfig()
// Logger is a global logger
Logger = newLogger()
// Router is a global HTTP muxer
Router = newRouter()
)
// New returns a Robot instance.
func New() (*Robot, error) {
return NewRobot()
}
// Hear a message
func Hear(pattern string, fn func(res *Response) error) handler {
return &Handler{Method: HEAR, Pattern: pattern, Run: fn}
}
// Respond creates a new listener for Respond messages
func Respond(pattern string, fn func(res *Response) error) handler {
return &Handler{Method: RESPOND, Pattern: pattern, Run: fn}
}
// Topic returns a new listener for Topic messages
func Topic(pattern string, fn func(res *Response) error) handler {
return &Handler{Method: TOPIC, Run: fn}
}
// Enter returns a new listener for Enter messages
func Enter(fn func(res *Response) error) handler {
return &Handler{Method: ENTER, Run: fn}
}
// Leave creates a new listener for Leave messages
func Leave(fn func(res *Response) error) handler {
return &Handler{Method: LEAVE, Run: fn}
}
// Close shuts down the robot. Unused?
func Close() error {
return nil
}