Beego语法的功能';Ctx.Input.GetData(';<;变量名>;';)';
我是新来的比戈和戈朗。我遇到了一个密码。如果有人能解释一下流程,那将非常有帮助。这是一个GETAPI。我认为Beego语法的功能';Ctx.Input.GetData(';<;变量名>;';)';,go,beego,Go,Beego,我是新来的比戈和戈朗。我遇到了一个密码。如果有人能解释一下流程,那将非常有帮助。这是一个GETAPI。我认为Prepare()就像一个过滤器。我不理解的是c.Ctx.Input.GetData(“customerid”)和c.Ctx.Input.GetData(“customergroupid”)函数。有人能解释一下GetData在做什么,以及我们如何向他们传递值吗 // URLMapping ... func (c *CampusHomeController) URLMapping() {
Prepare()
就像一个过滤器。我不理解的是c.Ctx.Input.GetData(“customerid”)
和c.Ctx.Input.GetData(“customergroupid”)
函数。有人能解释一下GetData
在做什么,以及我们如何向他们传递值吗
// URLMapping ...
func (c *CampusHomeController) URLMapping() {
c.Mapping("GetOne", c.GetOne)
}
func (c *CampusHomeController) Prepare() {
if c.Ctx.Input.GetData("customerid") == "" {
returnJSON := postCampusHomeJSON{}
returnJSON.Code = 403
returnJSON.Msg = "Invalid Session"
c.Data["json"] = &returnJSON
c.ServeJSON()
c.StopRun()
}
if c.Ctx.Input.GetData("customergroupid") == "" ||
c.Ctx.Input.GetData("customergroupid") == nil {
returnJSON := postCampusHomeJSON{}
returnJSON.Code = 404
returnJSON.Msg = "User not a campus manager"
c.Data["json"] = &returnJSON
c.ServeJSON()
c.StopRun()
}
}
GetData用于从控制器中的筛选器获取数据。它允许您传递值,而不仅仅是字符串 从Beego文档中: 获取数据 获取输入中的数据值 设置数据 设置输入中数据的值。GetData和SetData用于将数据从过滤器传递到控制器
所以过滤器是通过url传递的参数,比如/cm/profile?customergroupid=14?没有过滤器像其他web框架中的中间件。在api调用主体之前可以执行的东西,因此可以使用SetData方法在添加到
ctx.Input
的过滤器中查找“customergroupid”。然后通过ctx.Input.GetData
在api调用中检索。筛选文档: