Skip to content

Commit 06084cc

Browse files
committed
do not convert if already integers
1 parent db64aa2 commit 06084cc

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

main.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,31 @@ func add(storage Storage, name string, secret string, digits interface{}, interv
296296
}
297297
key := NewKey(ring, name)
298298
if digits != nil {
299-
key.Digits, err = convertStringToInt(digits.(string))
300-
if err != nil {
301-
return fmt.Errorf("cannot convert string to int: %w", err)
299+
switch v := digits.(type) {
300+
case int:
301+
key.Digits = v
302+
case string:
303+
key.Digits, err = convertStringToInt(v)
304+
if err != nil {
305+
return fmt.Errorf("cannot convert string to int: %w", err)
306+
}
307+
default:
308+
return fmt.Errorf("unsupported type for digits: %T", digits)
302309
}
303310
}
304311
if interval != nil {
305-
key.Interval, err = convertStringToInt(interval.(string))
306-
if err != nil {
307-
return fmt.Errorf("cannot convert string to int: %w", err)
312+
switch v := interval.(type) {
313+
case int:
314+
key.Interval = v
315+
case string:
316+
key.Interval, err = convertStringToInt(v)
317+
if err != nil {
318+
return fmt.Errorf("cannot convert string to int: %w", err)
319+
}
320+
default:
321+
return fmt.Errorf("unsupported type for interval: %T", interval)
308322
}
323+
309324
}
310325
err = key.Secret(secret)
311326
if err != nil {

0 commit comments

Comments
 (0)