func UserGateKeeper() (gk *govalidations.GateKeeper) { gk = govalidations.NewGateKeeper() gk.Add(govalidations.Regexp(func(object interface{}) interface{} { return object.(*User).Email }, regexp.MustCompile(`^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$`), "Email", "Must be a valid email")) gk.Add(govalidations.Presence(func(object interface{}) interface{} { return object.(*User).Username }, "Username", "Username can not be blank")) gk.Add(govalidations.Limitation(func(object interface{}) interface{} { return object.(*User).Username }, 0, 10, "Username", "Username can not be too long")) gk.Add(govalidations.Prohibition(func(object interface{}) interface{} { return object.(*User).Username }, 10, 20, "Username", "Username must less than 10 or more than 20")) gk.Add(govalidations.AvoidScriptTag(func(object interface{}) interface{} { return object.(*User).Username }, "Username", "Username can contains html script tag")) gk.Add(govalidations.Custom(func(object interface{}) bool { age := object.(*User).Age if age < 18 { return false } return true }, "Age", "You must be a grown man")) return }
func (agk *UserGateKeeper) AddPwdPresenceValidator() { agk.Add(govalidations.Presence(func(object interface{}) interface{} { return object.(*User).Password }, "Password", global.USER_08)) return }
func (this *EfficacyGateKeeper) AddNameValidator() { this.Add(govalidations.Presence(func(object interface{}) interface{} { return object.(*Efficacy).Name }, "Name", global.EFFICACY_02)) return }
func (agk *UserGateKeeper) AddNameValidator() { agk.Add(govalidations.Presence(func(object interface{}) interface{} { return object.(*User).Name }, "Name", global.USER_05)) agk.Add(govalidations.Limitation(func(object interface{}) interface{} { return object.(*User).Name }, 0, 20, "Name", global.USER_06)) return }
func (agk *UserGateKeeper) AddEmailValidator() { agk.Add(govalidations.Presence(func(object interface{}) interface{} { return object.(*User).Email }, "Email", global.USER_03)) agk.Add(govalidations.Regexp(func(object interface{}) interface{} { return object.(*User).Email }, regexp.MustCompile(global.EMAIL_REGEXP), "Email", global.USER_04)) return }
func (this *CategoryGateKeeper) AddNameAndLevelValidator() { this.Add(govalidations.Presence(func(object interface{}) interface{} { return object.(*Category).Name }, "Name", global.CATEGORY_02)) this.Add(govalidations.Custom(func(object interface{}) bool { return IsValidLevel(object.(*Category).Level) }, "Level", global.CATEGORY_03)) return }