Closed
Description
Package version eg. v8, v9:
v10.3.0
Issue, Question, or Enhancement:
When validating a string pointer with required_without
and omitempty
at the same time, calling Struct()
leads to panic.
Using omitempty
merely is ok. Validating a string instead of a string pointer is ok.
Code sample, to showcase or reproduce:
package main
import (
"log"
"github.com/go-playground/validator/v10"
)
type Sample struct {
Name string `validate:"omitempty,max=1024"`
ID string `validate:"required_without=Name,omitempty,max=64"`
}
type SampleWithPointer struct {
Name *string `validate:"omitempty,max=1024"`
ID *string `validate:"required_without=Name,omitempty,max=64"`
}
func main() {
name := "name"
s := &Sample{Name: name}
swp := &SampleWithPointer{Name: &name}
validate := validator.New()
if err := validate.Struct(s); err != nil {
log.Printf("Validate sample with error, %v", err)
}
if err := validate.Struct(swp); err != nil {
log.Printf("Validate SampeWithPointer with error, %v", err)
}
}
Metadata
Metadata
Assignees
Labels
No labels