Skip to content

Commit 44b6ddd

Browse files
committed
metric.go: move code about BOOL after type WDStatus struct.
1 parent 58843fe commit 44b6ddd

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

metric/metric.go

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,6 @@ import (
55
"strings"
66
)
77

8-
// BOOL is an int32 for structure align.
9-
type BOOL int32
10-
11-
// ToBool is used to convert to go bool.
12-
func (b BOOL) ToBool() bool {
13-
return b != 0
14-
}
15-
16-
func (b BOOL) String() string {
17-
if b.ToBool() {
18-
return "true"
19-
}
20-
return "false"
21-
}
22-
23-
// MarshalText is used to implement TextMarshaler interface.
24-
func (b BOOL) MarshalText() ([]byte, error) {
25-
return []byte(b.String()), nil
26-
}
27-
28-
// UnmarshalText is used to implement TextUnmarshaler interface.
29-
func (b *BOOL) UnmarshalText(data []byte) error {
30-
switch strings.ToLower(string(data)) {
31-
case "true":
32-
*b = BOOL(1)
33-
case "false":
34-
*b = BOOL(0)
35-
default:
36-
return errors.New("invalid BOOL value")
37-
}
38-
return nil
39-
}
40-
418
// Metrics contains status about runtime submodules.
429
type Metrics struct {
4310
Library LTStatus `toml:"library" json:"library"`
@@ -114,3 +81,36 @@ type WDStatus struct {
11481
NumNormal int64 `toml:"num_normal" json:"num_normal"`
11582
NumReset int64 `toml:"num_reset" json:"num_reset"`
11683
}
84+
85+
// BOOL is an int32 for structure align.
86+
type BOOL int32
87+
88+
// ToBool is used to convert to go bool.
89+
func (b BOOL) ToBool() bool {
90+
return b != 0
91+
}
92+
93+
func (b BOOL) String() string {
94+
if b.ToBool() {
95+
return "true"
96+
}
97+
return "false"
98+
}
99+
100+
// MarshalText is used to implement TextMarshaler interface.
101+
func (b BOOL) MarshalText() ([]byte, error) {
102+
return []byte(b.String()), nil
103+
}
104+
105+
// UnmarshalText is used to implement TextUnmarshaler interface.
106+
func (b *BOOL) UnmarshalText(data []byte) error {
107+
switch strings.ToLower(string(data)) {
108+
case "true":
109+
*b = BOOL(1)
110+
case "false":
111+
*b = BOOL(0)
112+
default:
113+
return errors.New("invalid BOOL value")
114+
}
115+
return nil
116+
}

0 commit comments

Comments
 (0)