-
Notifications
You must be signed in to change notification settings - Fork 2
/
sourcetype.go
72 lines (63 loc) · 1.5 KB
/
sourcetype.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
// Code generated by generate_enum; DO NOT EDIT.
// Package sourcetype is an enumeration of the states Upload, Snapshot
package sourcetype
import (
"encoding/json"
"fmt"
"reflect"
)
// Enum is an enumerated type
type Enum uint8
const (
// Upload is an enumeration for sourcetype.Enum
Upload Enum = iota + 1
// Snapshot is an enumeration for sourcetype.Enum
Snapshot
)
// ValidStrings is the set of strings that are valid inputs to ParseEnum
var ValidStrings = []string{
Upload.String(),
Snapshot.String(),
}
// String makes Enum satisfy the Stringer interface
func (i Enum) String() string {
tmp, err := i.MarshalText()
if err == nil {
return string(tmp)
}
return ""
}
// ParseEnum attempts to convert a string into a Enum
func ParseEnum(name string) (Enum, error) {
switch name {
case "upload":
return Upload, nil
case "snapshot":
return Snapshot, nil
}
var zero Enum
return zero, fmt.Errorf("%s is not a valid sourcetype.Enum", name)
}
// MarshalText implements the text marshaller method
func (i Enum) MarshalText() ([]byte, error) {
switch i {
case Upload:
return []byte("upload"), nil
case Snapshot:
return []byte("snapshot"), nil
}
return nil, fmt.Errorf("%d is not a valid sourcetype.Enum", i)
}
// UnmarshalText implements the text unmarshaller method
func (i *Enum) UnmarshalText(text []byte) error {
name := string(text)
tmp, err := ParseEnum(name)
if err != nil {
return &json.UnmarshalTypeError{
Value: name,
Type: reflect.TypeOf(*i),
}
}
*i = tmp
return nil
}