fix: drop probability handling

This commit is contained in:
Peter 2023-01-30 17:54:14 +01:00
parent 2d8df259cb
commit 46f412ac29
No known key found for this signature in database

View file

@ -42,7 +42,7 @@ func (g *Gapr) Map(input any) (any, error) {
case reflect.Struct, reflect.Interface: case reflect.Struct, reflect.Interface:
return g.mapStruct(t, v) return g.mapStruct(t, v)
case reflect.Slice, reflect.Array: case reflect.Slice, reflect.Array:
return g.mapSliceOrArray(t, v) return g.mapSliceOrArray(v)
default: default:
return nil, ErrNotSupportedType return nil, ErrNotSupportedType
} }
@ -103,7 +103,7 @@ func (g *Gapr) mapMap(t reflect.Type, v reflect.Value) (any, error) {
return mapped, nil return mapped, nil
} }
func (g *Gapr) mapSliceOrArray(t reflect.Type, v reflect.Value) (any, error) { func (g *Gapr) mapSliceOrArray(v reflect.Value) (any, error) {
var ( var (
length = v.Len() length = v.Len()
target = reflect.ValueOf(make([]any, length, length)) target = reflect.ValueOf(make([]any, length, length))
@ -142,7 +142,7 @@ func (g *Gapr) fieldMeta(f reflect.StructField) (drop bool, fieldName string, er
return false, "", err return false, "", err
} }
drop = g.rand.Float64() < 1.0-dropProbability drop = g.rand.Float64() < dropProbability
if tagSplit[1] != "" { if tagSplit[1] != "" {
fieldName = strings.TrimSpace(tagSplit[1]) fieldName = strings.TrimSpace(tagSplit[1])
} }