當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Controller.SetAction方法代碼示例

本文整理匯總了Golang中github.com/revel/revel.Controller.SetAction方法的典型用法代碼示例。如果您正苦於以下問題:Golang Controller.SetAction方法的具體用法?Golang Controller.SetAction怎麽用?Golang Controller.SetAction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/revel/revel.Controller的用法示例。


在下文中一共展示了Controller.SetAction方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: RouterFilter

func RouterFilter(c *revel.Controller, fc []revel.Filter) {
	// 補全controller部分
	path := c.Request.Request.URL.Path

	// Figure out the Controller/Action
	var route *revel.RouteMatch = revel.MainRouter.Route(c.Request.Request)
	if route == nil {
		c.Result = c.NotFound("No matching route found: " + c.Request.RequestURI)
		return
	}

	// The route may want to explicitly return a 404.
	if route.Action == "404" {
		c.Result = c.NotFound("(intentionally)")
		return
	}

	//----------
	// life start
	/*
		type URL struct {
		    Scheme   string
		    Opaque   string    // encoded opaque data
		    User     *Userinfo // username and password information
		    Host     string    // host or host:port
		    Path     string
		    RawQuery string // encoded query values, without '?'
		    Fragment string // fragment for references, without '#'
		}
	*/
	if route.ControllerName != "Static" {
		// api設置
		// leanote.com/api/user/get => ApiUser::Get
		//*       /api/login               ApiAuth.Login,  這裏的設置, 其實已經轉成了ApiAuth了
		if strings.HasPrefix(path, "/api") && !strings.HasPrefix(route.ControllerName, "Api") {
			route.ControllerName = "Api" + route.ControllerName
		} else if strings.HasPrefix(path, "/member") && !strings.HasPrefix(route.ControllerName, "Member") {
			// member設置
			route.ControllerName = "Member" + route.ControllerName
		}
		// end
	}

	// Set the action.
	if err := c.SetAction(route.ControllerName, route.MethodName); err != nil {
		c.Result = c.NotFound(err.Error())
		return
	}

	// Add the route and fixed params to the Request Params.
	c.Params.Route = route.Params

	// Add the fixed parameters mapped by name.
	// TODO: Pre-calculate this mapping.
	for i, value := range route.FixedParams {
		if c.Params.Fixed == nil {
			c.Params.Fixed = make(url.Values)
		}
		if i < len(c.MethodType.Args) {
			arg := c.MethodType.Args[i]
			c.Params.Fixed.Set(arg.Name, value)
		} else {
			revel.WARN.Println("Too many parameters to", route.Action, "trying to add", value)
			break
		}
	}

	fc[0](c, fc[1:])
}
開發者ID:intZz,項目名稱:leanote,代碼行數:69,代碼來源:Route.go


注:本文中的github.com/revel/revel.Controller.SetAction方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。