-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy paths.go
219 lines (210 loc) · 4.34 KB
/
s.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
-------------------------------------------------
Author : Zhang Fan
date: 2020/1/11
Description :
-------------------------------------------------
*/
package zstr
import (
"strconv"
)
type String string
func (m String) String() string {
return string(m)
}
func (m String) Val() string {
return string(m)
}
func (m String) Bytes() []byte {
return StringToBytes((*string)(&m))
}
func (m String) Bool() (bool, error) {
return ToBool(string(m))
}
func (m String) GetBool(def ...bool) bool {
if a, err := m.Bool(); err == nil {
return a
}
return len(def) > 0 && def[0]
}
func (m String) Int() (int, error) {
return strconv.Atoi(string(m))
}
func (m String) GetInt(def ...int) int {
if a, err := strconv.Atoi(string(m)); err == nil {
return a
}
if len(def) > 0 {
return def[0]
}
return 0
}
func (m String) Int8() (int8, error) {
n, err := strconv.ParseInt(string(m), 10, 8)
if err != nil {
return 0, err
}
return int8(n), nil
}
func (m String) GetInt8(def ...int8) int8 {
if a, err := strconv.ParseInt(string(m), 10, 8); err == nil {
return int8(a)
}
if len(def) > 0 {
return def[0]
}
return 0
}
func (m String) Int16() (int16, error) {
n, err := strconv.ParseInt(string(m), 10, 16)
if err != nil {
return 0, err
}
return int16(n), nil
}
func (m String) GetInt16(def ...int16) int16 {
if a, err := strconv.ParseInt(string(m), 10, 16); err == nil {
return int16(a)
}
if len(def) > 0 {
return def[0]
}
return 0
}
func (m String) Int32() (int32, error) {
n, err := strconv.ParseInt(string(m), 10, 32)
if err != nil {
return 0, err
}
return int32(n), nil
}
func (m String) GetInt32(def ...int32) int32 {
if a, err := strconv.ParseInt(string(m), 10, 32); err == nil {
return int32(a)
}
if len(def) > 0 {
return def[0]
}
return 0
}
func (m String) Int64() (int64, error) {
return strconv.ParseInt(string(m), 10, 64)
}
func (m String) GetInt64(def ...int64) int64 {
if a, err := strconv.ParseInt(string(m), 10, 64); err == nil {
return a
}
if len(def) > 0 {
return def[0]
}
return 0
}
func (m String) Uint() (uint, error) {
n, err := strconv.ParseUint(string(m), 10, 64)
if err != nil {
return 0, err
}
return uint(n), err
}
func (m String) GetUint(def ...uint) uint {
if a, err := strconv.ParseUint(string(m), 10, 64); err == nil {
return uint(a)
}
if len(def) > 0 {
return def[0]
}
return 0
}
func (m String) Uint8() (uint8, error) {
n, err := strconv.ParseUint(string(m), 10, 8)
if err != nil {
return 0, err
}
return uint8(n), nil
}
func (m String) GetUint8(def ...uint8) uint8 {
if a, err := strconv.ParseUint(string(m), 10, 8); err == nil {
return uint8(a)
}
if len(def) > 0 {
return def[0]
}
return 0
}
func (m String) Uint16() (uint16, error) {
n, err := strconv.ParseUint(string(m), 10, 16)
if err != nil {
return 0, err
}
return uint16(n), nil
}
func (m String) GetUint16(def ...uint16) uint16 {
if a, err := strconv.ParseUint(string(m), 10, 16); err == nil {
return uint16(a)
}
if len(def) > 0 {
return def[0]
}
return 0
}
func (m String) Uint32() (uint32, error) {
n, err := strconv.ParseUint(string(m), 10, 32)
if err != nil {
return 0, err
}
return uint32(n), nil
}
func (m String) GetUint32(def ...uint32) uint32 {
if a, err := strconv.ParseUint(string(m), 10, 32); err == nil {
return uint32(a)
}
if len(def) > 0 {
return def[0]
}
return 0
}
func (m String) Uint64() (uint64, error) {
return strconv.ParseUint(string(m), 10, 64)
}
func (m String) GetUint64(def ...uint64) uint64 {
if a, err := strconv.ParseUint(string(m), 10, 64); err == nil {
return a
}
if len(def) > 0 {
return def[0]
}
return 0
}
func (m String) Float32() (float32, error) {
f, err := strconv.ParseFloat(string(m), 32)
if err != nil {
return 0, err
}
return float32(f), nil
}
func (m String) GetFloat32(def ...float32) float32 {
if a, err := strconv.ParseFloat(string(m), 32); err == nil {
return float32(a)
}
if len(def) > 0 {
return def[0]
}
return 0
}
func (m String) Float64() (float64, error) {
return strconv.ParseFloat(string(m), 64)
}
func (m String) GetFloat64(def ...float64) float64 {
if a, err := strconv.ParseFloat(string(m), 64); err == nil {
return a
}
if len(def) > 0 {
return def[0]
}
return 0
}
// 扫描到任何, 输出变量不支持切片,数组,map,struct
func (m String) Scan(outPtr interface{}) error {
return Scan(string(m), outPtr)
}