go-ozzo / ozzo-validation

An idiomatic Go (golang) validation package. Supports configurable and extensible validation rules (validators) using normal language constructs instead of error-prone struct tags.
MIT License
3.73k stars 224 forks source link

".By()" method not working for Map validation #159

Open darienmiller88 opened 2 years ago

darienmiller88 commented 2 years ago

When attempting to validate a map field using the .By() method, the data (in this case an array) passed to the function no longer exists, even when I pass my map to the .Map() method by reference. How do I fix this?

func validateMap(reminder map[string]interface{}) error {
    fmt.Println("days:", reminder["days"])//This field, an array, is printed with all of its values in tac.
    return validation.Validate(&reminder,
        validation.Map(
            validation.Key("days", validation.By(test)).Optional(),
        ),
    )
}

func test(val interface{}) error{
    v, _ := val.([]string)

    fmt.Println("v:", v)//Here however, the array is empty.
    return nil
}