-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
82 lines (68 loc) · 2.01 KB
/
main.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
74
75
76
77
78
79
80
81
82
package options
import (
"time"
"github.com/jeroenrinzema/commander/internal/types"
)
const (
// DefaultRetries represents the default amount of retry attempts
DefaultRetries = 5
// DefaultTimeout represents the default timeout when awaiting a "sync" command to complete
DefaultTimeout = 5 * time.Second
)
// NewServerOptions applies the given serve options to construct a new server options definition
func NewServerOptions(options []ServerOption) (result *ServerOptions) {
result = &ServerOptions{}
for _, option := range options {
option.Apply(result)
}
return result
}
// ServerOption sets options such as timeouts, codec and retries
type ServerOption interface {
Apply(*ServerOptions)
}
// ServerOptions represent the available set of server options
type ServerOptions struct {
Timeout time.Duration
Retries int8
}
// NewGroupOptions applies the given serve options to construct a new group options definition
func NewGroupOptions(options []GroupOption) (result *GroupOptions) {
result = &GroupOptions{
Timeout: DefaultTimeout,
Retries: DefaultRetries,
}
for _, option := range options {
option.Apply(result)
}
return result
}
// GroupOption sets options such as topic definitions and timeouts
type GroupOption interface {
Apply(*GroupOptions)
}
// GroupOptions represent the available set of group options
type GroupOptions struct {
Timeout time.Duration
Retries int8
Topics []types.Topic
}
// NewHandlerOptions applies the given serve options to construct a new handle options definition
func NewHandlerOptions(options []HandlerOption) (result *HandlerOptions) {
// TODO: define default options
result = &HandlerOptions{}
for _, option := range options {
option.Apply(result)
}
return result
}
// HandlerOption sets options such as codec interfaces and timeouts
type HandlerOption interface {
Apply(*HandlerOptions)
}
// HandlerOptions represent the available set of handle options
type HandlerOptions struct {
Action string
MessageType types.MessageType
Callback types.HandlerFunc
}