have a nested structure coming from echo context, with this format:
type (
User struct {
Username string json:"username" validate:"required"
Password string json:"password" validate:"required"
}
UserLogin {
Email string json:"email"
User User
}
CustomValidator struct {
*validator.Validate
}
)
How can I validate nested UserLogin's User? I've found some solution but they did not match with this example
why not just do it manually?
yesterday I found a really useful function which is: func (*validator.Validate).Struct(s interface{}) error I changed the structure as follows: type ( User struct { Username string `json:"username" validate:"required"` Password string `json:"password" validate:"required"` } UserLogin { Email string `json:"email"` User User `json:"user"` } ) and then, after top level's struct (UserLogin) validated nested struct using v.Struct(u.User)
Обсуждают сегодня