@@ -13,6 +13,8 @@ const (
13
13
Bool = reflect .Bool
14
14
Int = reflect .Int
15
15
Uint = reflect .Uint
16
+ Int64 = reflect .Int64
17
+ Uint64 = reflect .Uint64
16
18
Float = reflect .Float64
17
19
String = reflect .String
18
20
)
@@ -95,6 +97,20 @@ var converters = map[reflect.Kind]converter{
95
97
}
96
98
return uint (val ), err
97
99
},
100
+ Int64 : func (v string ) (interface {}, error ) {
101
+ val , err := strconv .ParseInt (v , 0 , 64 )
102
+ if err != nil {
103
+ return nil , err
104
+ }
105
+ return val , err
106
+ },
107
+ Uint64 : func (v string ) (interface {}, error ) {
108
+ val , err := strconv .ParseUint (v , 0 , 64 )
109
+ if err != nil {
110
+ return nil , err
111
+ }
112
+ return val , err
113
+ },
98
114
Float : func (v string ) (interface {}, error ) {
99
115
return strconv .ParseFloat (v , 64 )
100
116
},
@@ -152,6 +168,12 @@ func IntOption(names ...string) Option {
152
168
func UintOption (names ... string ) Option {
153
169
return NewOption (Uint , names ... )
154
170
}
171
+ func Int64Option (names ... string ) Option {
172
+ return NewOption (Int64 , names ... )
173
+ }
174
+ func Uint64Option (names ... string ) Option {
175
+ return NewOption (Uint64 , names ... )
176
+ }
155
177
func FloatOption (names ... string ) Option {
156
178
return NewOption (Float , names ... )
157
179
}
@@ -209,6 +231,28 @@ func (ov *OptionValue) Uint() (value uint, found bool, err error) {
209
231
return val , ov .ValueFound , err
210
232
}
211
233
234
+ func (ov * OptionValue ) Int64 () (value int64 , found bool , err error ) {
235
+ if ov == nil || ! ov .ValueFound && ov .Value == nil {
236
+ return 0 , false , nil
237
+ }
238
+ val , ok := ov .Value .(int64 )
239
+ if ! ok {
240
+ err = fmt .Errorf ("expected type %T, got %T" , val , ov .Value )
241
+ }
242
+ return val , ov .ValueFound , err
243
+ }
244
+
245
+ func (ov * OptionValue ) Uint64 () (value uint64 , found bool , err error ) {
246
+ if ov == nil || ! ov .ValueFound && ov .Value == nil {
247
+ return 0 , false , nil
248
+ }
249
+ val , ok := ov .Value .(uint64 )
250
+ if ! ok {
251
+ err = fmt .Errorf ("expected type %T, got %T" , val , ov .Value )
252
+ }
253
+ return val , ov .ValueFound , err
254
+ }
255
+
212
256
func (ov * OptionValue ) Float () (value float64 , found bool , err error ) {
213
257
if ov == nil || ! ov .ValueFound && ov .Value == nil {
214
258
return 0 , false , nil
0 commit comments