-
Notifications
You must be signed in to change notification settings - Fork 5
/
boilerplate.go
82 lines (69 loc) · 2.69 KB
/
boilerplate.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 boilerplate_v1
import (
"errors"
"time"
"github.com/aperturerobotics/controllerbus/directive"
directive_proto "github.com/aperturerobotics/controllerbus/directive/proto"
"github.com/aperturerobotics/controllerbus/example/boilerplate"
)
// BoilerplateMessage returns the message to print.
func (b *Boilerplate) BoilerplateMessage() string {
return b.GetMessageText()
}
// GetNetworkedCodec returns the encoder / decoder for this directive.
func (b *Boilerplate) GetNetworkedCodec() directive.NetworkedCodec {
return directive_proto.GetProtobufCodec()
}
// GetName returns the directive's type name.
// This is not necessarily unique, and is primarily intended for display.
func (b *Boilerplate) GetName() string {
return "Boilerplate"
}
// Validate validates the directive.
// This is a cursory validation to see if the values "look correct."
func (b *Boilerplate) Validate() error {
if b.GetMessageText() == "" {
return errors.New("message text must be specified")
}
return nil
}
// GetValueOptions returns options relating to value handling.
func (b *Boilerplate) GetValueOptions() directive.ValueOptions {
return directive.ValueOptions{
// MaxValueCount indicates a maximum number of values to retrieve.
// The resolvers will be canceled when this many values are gathered.
// If zero, accepts infinite values.
MaxValueCount: 1,
// MaxValueHardCap indicates MaxValueCount is a hard cap. If it is not a
// hard cap, any values found after resolvers are canceled is accepted. If
// it is a hard cap, any values found after resolvers are canceled will be
// rejected.
MaxValueHardCap: true,
// UnrefDisposeDur is the duration to wait to dispose a directive after all
// references have been released.
UnrefDisposeDur: time.Millisecond * 10,
}
}
// IsEquivalent checks if the other directive is equivalent. If two
// directives are equivalent, and the new directive does not superceed the
// old, then the new directive will be merged (de-duplicated) into the old.
func (b *Boilerplate) IsEquivalent(other directive.Directive) bool {
ot, otOk := other.(boilerplate.Boilerplate)
if !otOk {
return false
}
return ot.BoilerplateMessage() == b.BoilerplateMessage()
}
// GetDebugVals returns the directive arguments as key/value pairs.
// This should be something like param1="test", param2="test".
// This is not necessarily unique, and is primarily intended for display.
func (b *Boilerplate) GetDebugVals() directive.DebugValues {
return directive.DebugValues{
"message": []string{b.BoilerplateMessage()},
}
}
var (
_ boilerplate.Boilerplate = ((*Boilerplate)(nil))
_ directive.Debuggable = ((*Boilerplate)(nil))
_ directive.DirectiveWithEquiv = ((*Boilerplate)(nil))
)