当前位置: 首页>>代码示例>>Golang>>正文


Golang Validation.ErrorMap方法代码示例

本文整理汇总了Golang中github.com/astaxie/beego/validation.Validation.ErrorMap方法的典型用法代码示例。如果您正苦于以下问题:Golang Validation.ErrorMap方法的具体用法?Golang Validation.ErrorMap怎么用?Golang Validation.ErrorMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/astaxie/beego/validation.Validation的用法示例。


在下文中一共展示了Validation.ErrorMap方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: validForm

func (this *baseRouter) validForm(form interface{}, names ...string) (bool, map[string]*validation.ValidationError) {
	// parse request params to form ptr struct
	utils.ParseForm(form, this.Input())

	// Put data back in case users input invalid data for any section.
	name := reflect.ValueOf(form).Elem().Type().Name()
	if len(names) > 0 {
		name = names[0]
	}
	this.Data[name] = form

	errName := name + "Error"

	// check form once
	if this.FormOnceNotMatch() {
		return false, nil
	}

	// Verify basic input.
	valid := validation.Validation{}
	if ok, _ := valid.Valid(form); !ok {
		errs := valid.ErrorMap()
		this.Data[errName] = &valid
		return false, errs
	}
	return true, nil
}
开发者ID:thuongdinh,项目名称:beegowebapp,代码行数:27,代码来源:router.go

示例2: Test_Valid

func Test_Valid(t *testing.T) {
	valid := validation.Validation{}
	user := &models.User{Username: "zhangsan", Password: "password"}
	b, err := valid.Valid(user)
	if err != nil {
		// handle error
		t.Log(err.Error())
		t.Error("Valid Error")
	}
	if !b {
		// validation does not pass
		// blabla...
		for _, err := range valid.Errors {
			t.Log(err.Field + "-" + err.String())
			t.Log(err.Key, err.Message)
		}

		t.Log("ppppp")
		for k, v := range valid.ErrorMap() {
			t.Log(k, "=", v)
		}
		t.Error("Valid Error")
	}

	t.Log("Valid not has errors")
}
开发者ID:11101171,项目名称:violence,代码行数:26,代码来源:user_test.go

示例3: AgentOperate

func (this *AdminController) AgentOperate() {
	if this.Ctx.Input.Method() == "GET" {
		agentId := this.Ctx.Input.Param(":agentId")
		beego.Info("agentId", agentId)

		agent := &models.Agent{}
		if agentId != "" {
			agent = agent.SelectOneById(agentId)
		}
		this.Data["AgentForm"] = agent
		this.Layout = "layout/main.html"
		this.TplNames = "admin/agent/operate.html"
	} else {
		agent := &models.Agent{}
		if err := this.ParseForm(agent); err != nil {
			this.Data["jons"] = err
			this.ServeJson()
			return
		}

		agent.UserId = this.GetAuthUser().Id
		var valid *validation.Validation
		if agent.Id == "" {
			valid = agent.ValidAgentAdd()
		} else {
			valid = agent.ValidAgentEdit()
		}

		b, _ := valid.Valid(agent)
		if !b {
			this.Data["ErrorMap"] = valid.ErrorMap()
			this.Data["ErrorForm"] = agent
			for k, v := range valid.ErrorMap() {
				beego.Info(k, " Error is ", "-", v.Value, "-", v.Field, "-", v.Tmpl, "-", v.Key, "=", v.Message, "-")
			}
			this.Layout = "layout/main.html"
			this.TplNames = "admin/agent/operate.html"
			return
		}

		var message string
		if agent.Id == "" {
			message = "新增ssh成功"
			if err := agent.InsertOne(); err != nil {
				this.ErrDataBase("新增ssh失败")
				return
			}
		} else {
			message = "更新ssh成功"
			if err := agent.UpdateOne(); err != nil {
				this.ErrDataBase("更新ssh失败")
				return
			}
		}

		this.DoSuccess(message, "/admin/agent/list")

	}
}
开发者ID:11101171,项目名称:violence,代码行数:59,代码来源:admin.go

示例4: Operate

func (this *ServerController) Operate() {
	if this.Ctx.Input.IsGet() {
		serverId := this.Ctx.Input.Param(":serverId")
		beego.Debug("serverId=>", serverId)
		server := &models.Server{}
		if serverId != "" {
			server = server.SelectOneById(serverId)
		}
		this.Data["ServerForm"] = server
		this.Layout = "layout/main.html"
		this.TplNames = "admin/server/operate.html"
	} else {
		server := models.Server{}
		if err := this.ParseForm(&server); err != nil {
			this.ErrInputData("数据错误")
		}

		user := this.GetAuthUser()
		server.UserId = user.Id
		// beego.Debug("server=>",
		// fmt.Sprintf("%+v", server),
		// )
		var valid *validation.Validation
		if server.Id == "" {
			valid = server.ValidServerAdd()
		} else {
			valid = server.ValidServerEdit()
		}

		b, _ := valid.Valid(&server)
		if !b {
			this.Data["ErrorMap"] = valid.ErrorMap()
			this.Data["ErrorForm"] = server
			this.Layout = "layout/main.html"
			this.TplNames = "admin/server/operate.html"
			return
		}

		var message string
		if server.Id == "" {
			message = "新增API配置主题成功"
			if err := server.InsertOne(); err != nil {
				this.ErrDataBase("新增API配置主题失败")
				return
			}
		} else {
			message = "更新API配置主题成功"
			if err := server.UpdateOne(); err != nil {
				this.ErrDataBase("更新API配置主题失败")
				return
			}
		}
		services.GetInstance().CacheService.PutServerContent(server.Id, server.Content)
		this.DoSuccess(message, "/admin/server/index")

	}

}
开发者ID:11101171,项目名称:violence,代码行数:58,代码来源:server.go

示例5: UserOperate

// @router /user/operate/?:userId [get,post]
func (this *AdminController) UserOperate() {
	if this.Ctx.Input.Method() == "GET" {
		userId := this.Ctx.Input.Param(":userId")
		beego.Info("userId", userId)

		user := &models.User{}
		if userId != "" {
			user = user.SelectOneById(userId)
		}
		this.Data["UserForm"] = user
		this.Layout = "layout/main.html"
		this.TplNames = "admin/user/operate.html"
		return
	} else {
		user := &models.User{}
		if err := this.ParseForm(user); err != nil {
			this.Data["jons"] = err
			this.ServeJson()
			return
		}
		var valid *validation.Validation
		if user.Id == "" {
			valid = user.ValidUserAdd()
		} else {
			valid = user.ValidUserEdit()
		}

		b, _ := valid.Valid(user)
		if !b {
			this.Data["ErrorMap"] = valid.ErrorMap()
			this.Data["ErrorForm"] = user
			for k, v := range valid.ErrorMap() {
				beego.Info(k, " Error is ", "-", v.Value, "-", v.Field, "-", v.Tmpl, "-", v.Key, "=", v.Message, "-")
			}
			this.Layout = "layout/main.html"
			this.TplNames = "admin/user/operate.html"
			return
		}

		var message string
		if user.Id == "" {
			message = "新增用户成功"
			if err := user.InsertOne(); err != nil {
				this.ErrDataBase("新增用户失败")
				return
			}
		} else {
			message = "更新用户成功"
			if err := user.UpdateOne(); err != nil {
				this.ErrDataBase("更新用户失败")
				return
			}
		}

		this.DoSuccess(message, "/admin/user/list")
	}

}
开发者ID:11101171,项目名称:violence,代码行数:59,代码来源:admin.go

示例6: CmdOperate

func (this *AdminController) CmdOperate() {
	if this.Ctx.Input.Method() == "GET" {
		cmdId := this.Ctx.Input.Param(":cmdId")
		agentId := this.Ctx.Input.Param(":agentId")
		beego.Info("cmdId", cmdId)

		cmd := &models.Cmd{}
		if cmdId != "" {
			cmd = cmd.SelectOneById(cmdId)
		}
		cmd.AgentId = agentId
		this.Data["CmdForm"] = cmd
		this.Layout = "layout/main.html"
		this.TplNames = "admin/cmd/operate.html"
	} else {
		cmd := &models.Cmd{}
		if err := this.ParseForm(cmd); err != nil {
			this.Data["jons"] = err
			this.ServeJson()
			return
		}
		var valid *validation.Validation
		if cmd.Id == "" {
			valid = cmd.ValidCmdAdd()
		} else {
			valid = cmd.ValidCmdEdit()
		}

		b, _ := valid.Valid(cmd)
		if !b {
			this.Data["ErrorMap"] = valid.ErrorMap()
			this.Data["ErrorForm"] = cmd
			this.Layout = "layout/main.html"
			this.TplNames = "admin/cmd/operate.html"
			return
		}

		var message string
		if cmd.Id == "" {
			message = "新增cmd成功"
			if err := cmd.InsertOne(); err != nil {
				this.ErrDataBase("新增cmd失败")
				return
			}
		} else {
			message = "更新cmd成功"
			if err := cmd.UpdateOne(); err != nil {
				this.ErrDataBase("更新ssh失败")
				return
			}
		}

		this.DoSuccess(message, "/admin/agent/list")

	}
}
开发者ID:11101171,项目名称:violence,代码行数:56,代码来源:admin.go

示例7: Test_ValidUserAdd

func Test_ValidUserAdd(t *testing.T) {
	user := models.User{Username: "zhangsan", Password: "password"}
	var valid *validation.Validation
	valid = user.ValidUserAdd()
	b, _ := valid.Valid(user)
	if !b {
		for k, v := range valid.ErrorMap() {
			beego.Info(k, " Error is ", "-", v.Value, "-", v.Field, "-", v.Tmpl, "-", v.Key, "=")
		}
	}

}
开发者ID:11101171,项目名称:violence,代码行数:12,代码来源:user_test.go


注:本文中的github.com/astaxie/beego/validation.Validation.ErrorMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。