-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathoptions.go
73 lines (56 loc) · 1.67 KB
/
options.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package commander
import (
"time"
"github.com/jeroenrinzema/commander/internal/options"
"github.com/jeroenrinzema/commander/internal/types"
)
type timeout struct {
duration time.Duration
}
func (t *timeout) Apply(options *options.GroupOptions) {
options.Timeout = t.duration
}
// WithAwaitTimeout returns a GroupOption that configures the timeout period for the given group
func WithAwaitTimeout(d time.Duration) options.GroupOption {
return &timeout{d}
}
type action struct {
name string
}
func (a *action) Apply(options *options.HandlerOptions) {
options.Action = a.name
}
// WithAction returns a HandleOptions that configures the action handle
func WithAction(n string) options.HandlerOption {
return &action{n}
}
type messageType struct {
value types.MessageType
}
func (t *messageType) Apply(options *options.HandlerOptions) {
options.MessageType = t.value
}
// WithMessageType returns a HandleOptions that configures the message type handle
func WithMessageType(t types.MessageType) options.HandlerOption {
return &messageType{t}
}
type callback struct {
handle types.HandlerFunc
}
func (c *callback) Apply(options *options.HandlerOptions) {
options.Callback = c.handle
}
// WithCallback returns a HandleOptions that configures the callback method for a given handle
func WithCallback(h types.HandlerFunc) options.HandlerOption {
return &callback{h}
}
type schema struct {
handle func() interface{}
}
func (s *schema) Apply(options *options.HandlerOptions) {
options.Schema = s.handle
}
// WithMessageSchema returns a HandleOptions that configures the message schema for a handle
func WithMessageSchema(f func() interface{}) options.HandlerOption {
return &schema{f}
}