-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbackground.go
38 lines (31 loc) · 997 Bytes
/
background.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
package hugot
import "context"
// BackgroundHandler gets run when the bot starts listening. They are
// intended for publishing messages that are not in response to any
// specific incoming message.
type BackgroundHandler interface {
Describer
StartBackground(ctx context.Context, w ResponseWriter)
}
type baseBackgroundHandler struct {
name string
desc string
bhf BackgroundFunc
}
// BackgroundFunc describes the calling convention for Background handlers
type BackgroundFunc func(ctx context.Context, w ResponseWriter)
// NewBackgroundHandler wraps f up as a BackgroundHandler with the name and
// description provided.
func NewBackgroundHandler(name, desc string, f BackgroundFunc) BackgroundHandler {
return &baseBackgroundHandler{
name: name,
desc: desc,
bhf: f,
}
}
func (bbh *baseBackgroundHandler) Describe() (string, string) {
return bbh.name, bbh.desc
}
func (bbh *baseBackgroundHandler) StartBackground(ctx context.Context, w ResponseWriter) {
bbh.bhf(ctx, w)
}