-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.go
44 lines (39 loc) · 1.03 KB
/
status.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
package dataset
import (
"strconv"
"strings"
)
type Status struct {
IsErr bool `json:"is_error"`
Message string `json:"message"`
Status int `json:"status"`
Err string `json:"error,omitempty"`
Request string `json:"request"`
Trace string `json:"trace,omitempty"`
}
// Status implements the Error interface
func (e *Status) Error() string {
return e.String()
}
// Status implements the Stringer interface
// Using fmt package here caused stack overflow
func (e *Status) String() string {
var result = make([]string, 0)
result = append(result, `{ "is_error": `+strconv.FormatBool(e.IsErr))
result = append(result, ` "status": `+strconv.Itoa(e.Status))
result = append(result, ` "message": "`+e.Message+`"`)
result = append(result, ` "error": "`+e.Err+`" }`)
return strings.Join(result, ",")
}
func SafeVerseNum(number string) int {
var result []rune
for _, chr := range number {
if chr >= '0' && chr <= '9' {
result = append(result, chr)
} else {
break
}
}
num, _ := strconv.Atoi(string(result))
return num
}