triggertype json enums for yaml parsing

pull/39/head
Karolis Rusenas 2017-07-20 20:39:57 +01:00
parent 59693d6a48
commit 0daa056a7e
1 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,56 @@
// generated by jsonenums -type=TriggerType; DO NOT EDIT
package types
import (
"encoding/json"
"fmt"
)
var (
_TriggerTypeNameToValue = map[string]TriggerType{
"TriggerTypeDefault": TriggerTypeDefault,
"TriggerTypePoll": TriggerTypePoll,
}
_TriggerTypeValueToName = map[TriggerType]string{
TriggerTypeDefault: "TriggerTypeDefault",
TriggerTypePoll: "TriggerTypePoll",
}
)
func init() {
var v TriggerType
if _, ok := interface{}(v).(fmt.Stringer); ok {
_TriggerTypeNameToValue = map[string]TriggerType{
interface{}(TriggerTypeDefault).(fmt.Stringer).String(): TriggerTypeDefault,
interface{}(TriggerTypePoll).(fmt.Stringer).String(): TriggerTypePoll,
}
}
}
// MarshalJSON is generated so TriggerType satisfies json.Marshaler.
func (r TriggerType) MarshalJSON() ([]byte, error) {
if s, ok := interface{}(r).(fmt.Stringer); ok {
return json.Marshal(s.String())
}
s, ok := _TriggerTypeValueToName[r]
if !ok {
return nil, fmt.Errorf("invalid TriggerType: %d", r)
}
return json.Marshal(s)
}
// UnmarshalJSON is generated so TriggerType satisfies json.Unmarshaler.
func (r *TriggerType) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("TriggerType should be a string, got %s", data)
}
v, ok := _TriggerTypeNameToValue[s]
if !ok {
return fmt.Errorf("invalid TriggerType %q", s)
}
*r = v
return nil
}