You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func (u *User) Validate() field.ErrorList {
val := validation.NewValidator(u)
......
}
func (u *User) ValidateUpdate() field.ErrorList {
val := validation.NewValidator(u)
.......
}
// Validate validates that a secret object is valid.
func (s *Secret) Validate() field.ErrorList {
val := validation.NewValidator(s)
return val.Validate()
}
// Validate validates that a policy object is valid.
func (p *Policy) Validate() field.ErrorList {
val := validation.NewValidator(p)
return val.Validate()
}
in the end
func NewValidator(data interface{}) *Validator {
result := validator.New()
......
}
//New returns a new instance of 'validate' with sane defaults. Validate is designed to be thread-safe and used as a singleton instance. //It caches information about your struct and validations, in essence only parsing your validation tags once per struct type. Using //multiple instances neglects the benefit of caching.
validator.New()
l think result can be single instance,there is no need to create an validator instance everytime NewValidator function is called
Am l right?
The text was updated successfully, but these errors were encountered:
54cheng
changed the title
why always new NewValidator?
why always new Validator?
Feb 19, 2023
github.com/marmotedu/api/apiserver/v1/validate.go
func (u *User) Validate() field.ErrorList {
val := validation.NewValidator(u)
......
}
func (u *User) ValidateUpdate() field.ErrorList {
val := validation.NewValidator(u)
.......
}
// Validate validates that a secret object is valid.
func (s *Secret) Validate() field.ErrorList {
val := validation.NewValidator(s)
}
// Validate validates that a policy object is valid.
func (p *Policy) Validate() field.ErrorList {
val := validation.NewValidator(p)
}
in the end
func NewValidator(data interface{}) *Validator {
result := validator.New()
......
}
//New returns a new instance of 'validate' with sane defaults. Validate is designed to be thread-safe and used as a singleton instance. //It caches information about your struct and validations, in essence only parsing your validation tags once per struct type. Using //multiple instances neglects the benefit of caching.
validator.New()
l think result can be single instance,there is no need to create an validator instance everytime NewValidator function is called
Am l right?
The text was updated successfully, but these errors were encountered: