Ejemplo n.º 1
0
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"))
	}
}
Ejemplo n.º 2
0
func init() {
	govalidator.SetFieldsRequiredByDefault(true)
	govalidator.CustomTypeTagMap.Set("stellar_accountid", govalidator.CustomTypeValidator(isStellarAccountID))
	govalidator.CustomTypeTagMap.Set("stellar_seed", govalidator.CustomTypeValidator(isStellarSeed))

}
Ejemplo n.º 3
-1
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)
}