ozzo-validation
ozzo-validation copied to clipboard
Configurable valuer interface
In my application, I actually don't want sql.Valuer to be expanding my values, since I have a struct that expands to a JSON object in the DB. When I run validations, this means that it's validating against the JSON string and not the actual object. I'd like to be able to turn off this translation. Even better would be a way to pass in the interface or function that is able to convert specific validation objects.
Hi @oliy, I met the same problem as you.
Currently, the Indirect()
works on all the type who implements driver.Valuer
. This doesn't make much sense, I mean sometimes, the output of driver.Valuer.Value()
is what we write directly to DB, but not for validation, right?
e.g.
type MySice []MyStruct
func (s MySice) Value() (driver.Value, error) {
return json.Marshal(s)
}
type Foo struct {
MySice
}
// This will serialize `MySice` into JSON and get error on `validation.Length(1, 3)`.
validation.ValidateStruct(foo, validation.Field(&foo.MySice, validation.Length(1, 3)))
Would you like to give us some advice? @qiangxue