func (user *User) Validate(db *gorm.DB) { govalidator.CustomTypeTagMap.Set("uniqEmail", govalidator.CustomTypeValidator(func(email interface{}, context interface{}) bool { var count int if db.Model(&User{}).Where("email = ?", email).Count(&count); count == 0 || email == "" { return true } return false })) if user.Name == "invalid" { db.AddError(validations.NewError(user, "Name", "invalid user name")) } }
func init() { govalidator.SetFieldsRequiredByDefault(true) govalidator.CustomTypeTagMap.Set("stellar_accountid", govalidator.CustomTypeValidator(isStellarAccountID)) govalidator.CustomTypeTagMap.Set("stellar_seed", govalidator.CustomTypeValidator(isStellarSeed)) }
func init() { valid.CustomTypeTagMap.Set("btw_zero_and_one", valid.CustomTypeValidator(btwZeroAndOne)) valid.CustomTypeTagMap.Set("greater_zero", valid.CustomTypeValidator(greaterZeroValidator)) valid.CustomTypeTagMap.Set("environment", valid.CustomTypeValidator(envValidator)) valid.TagMap["email_val"] = valid.Validator(emailValidator) }