Skip to content

Commit

Permalink
Add float types to deafults
Browse files Browse the repository at this point in the history
  • Loading branch information
leodeim committed Jan 14, 2024
1 parent 4d46eda commit fa93d06
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ func setValue(field reflect.Value, val string) {
if val, err := strconv.Atoi(val); err == nil {
field.Set(reflect.ValueOf(int(val)).Convert(field.Type()))
}
case reflect.Float32:
if val, err := strconv.ParseFloat(val, 32); err == nil {
field.Set(reflect.ValueOf(float32(val)).Convert(field.Type()))
}
case reflect.Float64:
if val, err := strconv.ParseFloat(val, 64); err == nil {
field.Set(reflect.ValueOf(float64(val)).Convert(field.Type()))
}
case reflect.String:
field.Set(reflect.ValueOf(val).Convert(field.Type()))
case reflect.Bool:
Expand Down

0 comments on commit fa93d06

Please sign in to comment.