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


Golang Controller.RenderJson方法代碼示例

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


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

示例1: AuthInterceptor

func AuthInterceptor(c *revel.Controller) revel.Result {
	// 全部變成首字大寫
	/*
		var controller = strings.Title(c.Name)
		var method = strings.Title(c.MethodName)
		// 是否需要驗證?
		if !needValidate(controller, method) {
			return nil
		}
	*/

	// 驗證是否已登錄
	// 必須是管理員
	if username, ok := c.Session["Username"]; ok && username == configService.GetAdminUsername() {
		return nil // 已登錄
	}

	// 沒有登錄, 判斷是否是ajax操作
	if c.Request.Header.Get("X-Requested-With") == "XMLHttpRequest" {
		re := info.NewRe()
		re.Msg = "NOTLOGIN"
		return c.RenderJson(re)
	}

	return c.Redirect("/login")
}
開發者ID:ClaudeXin,項目名稱:leanote,代碼行數:26,代碼來源:init.go

示例2: AuthFilter

/*
Filter AuthFilter is Revel Filter for JWT Auth Token verification
Register it in the revel.Filters in <APP_PATH>/app/init.go

Add jwt.AuthFilter anywhere deemed appropriate, it must be register after revel.PanicFilter

	revel.Filters = []revel.Filter{
		revel.PanicFilter,
		...
		jwt.AuthFilter,		// JWT Auth Token verification for Request Paths
		...
	}

Note: If everything looks good then Claims map made available via c.Args
and can be accessed using c.Args[jwt.TOKEN_CLAIMS_KEY]
*/
func AuthFilter(c *revel.Controller, fc []revel.Filter) {
	if !anonymousPaths.MatchString(c.Request.URL.Path) {
		token, err := ParseFromRequest(c.Request.Request)
		if err == nil && token.Valid && !IsInBlocklist(GetAuthToken(c.Request)) {
			c.Args[TOKEN_CLAIMS_KEY] = token.Claims

			fc[0](c, fc[1:]) // everything looks good, move on
		} else {
			if ve, ok := err.(*jwt.ValidationError); ok {
				if ve.Errors&jwt.ValidationErrorMalformed != 0 {
					revel.ERROR.Println("That's not even a token")
				} else if ve.Errors&(jwt.ValidationErrorExpired|jwt.ValidationErrorNotValidYet) != 0 {
					revel.ERROR.Println("Timing is everything, Token is either expired or not active yet")
				} else {
					revel.ERROR.Printf("Couldn't handle this token: %v", err)
				}
			} else {
				revel.ERROR.Printf("Couldn't handle this token: %v", err)
			}

			c.Response.Status = http.StatusUnauthorized
			c.Response.Out.Header().Add("WWW-Authenticate", Realm)
			c.Result = c.RenderJson(map[string]string{
				"id":      "unauthorized",
				"message": "Invalid or token is not provided",
			})

			return
		}
	}

	fc[0](c, fc[1:]) //not applying JWT auth filter due to anonymous path
}
開發者ID:oblank,項目名稱:jwtauth,代碼行數:49,代碼來源:jwt.go

示例3: checkDataTypeParam

func checkDataTypeParam(c *revel.Controller) revel.Result {
	dataType, ok := c.Params.Values["dataType"]
	if ok && dataType[0] != "" {
		if _, ok := database.SynchronizationTypes[dataType[0]]; !ok {
			c.Response.Status = 400
			return c.RenderJson("wrong dataType attribute")
		}
		return nil
	}
	c.Response.Status = 400
	return c.RenderJson("mandatory parameter dataType is not present")
}
開發者ID:rtm7777,項目名稱:rozklad_cdtu,代碼行數:12,代碼來源:synchronization.go

示例4: returnMessage

func returnMessage(c *revel.Controller, message interface{}, err error) revel.Result {
	result := &opResult{}
	if err != nil {
		result.Result = Error
		result.Message = err.Error()
		revel.WARN.Fatalln(err)
	} else {
		result.Result = Success
		result.Message = message
	}

	return c.RenderJson(result)
}
開發者ID:qtzheng,項目名稱:SIMP,代碼行數:13,代碼來源:basecollection.go

示例5: GetGridJson

func GetGridJson(c *revel.Controller, count int, data interface{}) revel.Result {
	json := &GridJson{count, data}
	return c.RenderJson(json)
}
開發者ID:qtzheng,項目名稱:SIMP,代碼行數:4,代碼來源:basecollection.go


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