-
Notifications
You must be signed in to change notification settings - Fork 12
/
taskstate_jsonenums.go
75 lines (67 loc) · 2.5 KB
/
taskstate_jsonenums.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
// Copyright 2020 The searKing Author. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// generated by jsonenums -type TaskState; DO NOT EDIT
package resilience
import (
"encoding/json"
"fmt"
)
var (
_TaskStateNameToValue = map[string]TaskState{
"TaskStateNew": TaskStateNew,
"TaskStateRunning": TaskStateRunning,
"TaskStateDoneErrorHappened": TaskStateDoneErrorHappened,
"TaskStateDoneNormally": TaskStateDoneNormally,
"TaskStateDormancy": TaskStateDormancy,
"TaskStateDeath": TaskStateDeath,
"TaskStateButt": TaskStateButt,
}
_TaskStateValueToName = map[TaskState]string{
TaskStateNew: "TaskStateNew",
TaskStateRunning: "TaskStateRunning",
TaskStateDoneErrorHappened: "TaskStateDoneErrorHappened",
TaskStateDoneNormally: "TaskStateDoneNormally",
TaskStateDormancy: "TaskStateDormancy",
TaskStateDeath: "TaskStateDeath",
TaskStateButt: "TaskStateButt",
}
)
func init() {
var v TaskState
if _, ok := interface{}(v).(fmt.Stringer); ok {
_TaskStateNameToValue = map[string]TaskState{
interface{}(TaskStateNew).(fmt.Stringer).String(): TaskStateNew,
interface{}(TaskStateRunning).(fmt.Stringer).String(): TaskStateRunning,
interface{}(TaskStateDoneErrorHappened).(fmt.Stringer).String(): TaskStateDoneErrorHappened,
interface{}(TaskStateDoneNormally).(fmt.Stringer).String(): TaskStateDoneNormally,
interface{}(TaskStateDormancy).(fmt.Stringer).String(): TaskStateDormancy,
interface{}(TaskStateDeath).(fmt.Stringer).String(): TaskStateDeath,
interface{}(TaskStateButt).(fmt.Stringer).String(): TaskStateButt,
}
}
}
// MarshalJSON is generated so TaskState satisfies json.Marshaler.
func (r TaskState) MarshalJSON() ([]byte, error) {
if s, ok := interface{}(r).(fmt.Stringer); ok {
return json.Marshal(s.String())
}
s, ok := _TaskStateValueToName[r]
if !ok {
return nil, fmt.Errorf("invalid TaskState: %d", r)
}
return json.Marshal(s)
}
// UnmarshalJSON is generated so TaskState satisfies json.Unmarshaler.
func (r *TaskState) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("TaskState should be a string, got %s", data)
}
v, ok := _TaskStateNameToValue[s]
if !ok {
return fmt.Errorf("invalid TaskState %q", s)
}
*r = v
return nil
}