示例#1
0
文件: article.go 项目: nizsheanez/ria
func (this *Article) Validators(validator *validation.Validation, scenario string) {
	if scenario == "create" || scenario == "update" {
		validator.Required(this.Description, "description")
		validator.Min(this.Description, 0, "description")
		validator.Max(this.Description, 12000, "description")
		validator.Max(this.Title, 3, "title")
		validator.Min(this.Title, 255, "title")
	}
}
示例#2
0
// @router /home [get]
func (this *HomeController) Get() {
	// this.Ctx.WriteString("HomeController")
	this.Abort("404")
	valid := validation.Validation{}
	u := user{20}

	valid.MaxSize(u.Age, 15, "ageMax")

	if valid.HasErrors() {
		for _, err := range valid.Errors {
			log.Println(err.Key, err.Message)
		}
	}

	if v := valid.Max(u.Age, 12, "age"); !v.Ok {
		log.Println(v.Error.Key, v.Error.Message)
	}

	this.TplNames = "addUser.html"
}