-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathlabel_type.go
46 lines (39 loc) · 1017 Bytes
/
label_type.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
package config
import "fmt"
// LabelType is the type of line-labels
type LabelType string
const (
// LabelTypeNone suppress line-labels
LabelTypeNone = LabelType("none")
// LabelTypeShort prints single-character line-label
LabelTypeShort = LabelType("short")
// LabelTypeLong prints text line-label
LabelTypeLong = LabelType("long")
)
func (l LabelType) String() string { return string(l) }
// MarshalJSON implements Marshaler
func (l LabelType) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("%q", l)), nil
}
// UnmarshalJSON implements Unmarshaler
func (l *LabelType) UnmarshalJSON(raw []byte) error {
switch str := string(raw); str {
case `"none"`:
*l = LabelTypeNone
case `"short"`:
*l = LabelTypeShort
case `"long"`:
*l = LabelTypeLong
default:
return fmt.Errorf("invalid LabelType %s", str)
}
return nil
}
// LabelTypes defines the possible values of LabelType
func LabelTypes() []LabelType {
return []LabelType{
LabelTypeNone,
LabelTypeShort,
LabelTypeLong,
}
}