I'm using the v9 version
I have a struct in which I have a string field, which is optional: I allow it to be empty, but if it isn't empty, I want to enforce the URL format.
I simply did a validate:"url" without putting the required tag, thinking that it'd allow empty data, but it doesn't.
How can I handle that ?
type Contributor struct {
LastName string `validate:"required,min=3"`
FirstName string `validate:"required,min=3"`
Email string `validate:"required,email"`
PersonalWebsite string `validate:"url"` // If it's not required, it'll still crash as it isn't URL format.
PhoneNumber string
Role string `validate:"" gorm:"size:50"`
}
Hey @IvanDelsinne as the documentation states I think you're looking for omitempty
Most helpful comment
Hey @IvanDelsinne as the documentation states I think you're looking for
omitempty