Closed hazcod closed 3 years ago
The tag name is incorrect. Instead of "validate" it needs to be "valid". I believe the example below shows the behavior you are expecting.
type Custom struct {
Id uint32 `pg:"id,pk" json:"id" valid:"null"`
}
func main() {
x := Custom{Id: 1}
ok, err := govalidator.ValidateStruct(x)
fmt.Println(ok, err)
y := Custom{}
ok, err = govalidator.ValidateStruct(y)
fmt.Println(ok, err)
}
Output:
false id: 1 does not validate as null
true <nil>
Hi, for my API endpoint I need to make sure that people do not try to use their own primary keys. This is done via:
But this still goes through if I post with
{"id":1}