-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.go
74 lines (66 loc) · 1.21 KB
/
interface.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
package gomap
import "bytes"
// Mapper ...
type Mapper interface {
ToMap() Map
}
// XMLer ...
type XMLer interface {
ParseXML([]byte) error
ToXML() []byte
}
// JSONer ...
type JSONer interface {
ParseJson([]byte) error
ToJSON() (v []byte, err error)
}
// Stringer ...
type Stringer interface {
String() string
}
//ParseNumber parse interface to number
func ParseNumber(v interface{}) (float64, bool) {
switch v0 := v.(type) {
case float64:
return v0, true
case float32:
return float64(v0), true
}
return 0, false
}
//ParseInt parse interface to int64
func ParseInt(v interface{}) (int64, bool) {
switch v0 := v.(type) {
case int:
return int64(v0), true
case int32:
return int64(v0), true
case int64:
return v0, true
case uint:
return int64(v0), true
case uint32:
return int64(v0), true
case uint64:
return int64(v0), true
case float64:
return int64(v0), true
case float32:
return int64(v0), true
default:
}
return 0, false
}
//ParseString parse interface to string
func ParseString(v interface{}) (string, bool) {
switch v0 := v.(type) {
case string:
return v0, true
case []byte:
return string(v0), true
case bytes.Buffer:
return v0.String(), true
default:
}
return "", false
}