I saw a tutorial on internet and it created a validator as a pointer but never explained. Is there any underlying purpose of doing this?
// Validation contains
type Validation struct {
validate *validator.Validate
}
// NewValidation creates a new Validation type
func NewValidation() *Validation {
validate := validator.New()
validate.RegisterValidation("sku", validateSKU)
return &Validation{validate}
}
CodePudding user response:
It is returning the pointer of Validate struct with the default values. and it is type of *validator.Validate
validate := validator.New()
func New() *Validate { }