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


Golang Context.IndentedJSON方法代碼示例

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


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

示例1: Handler

// Handler is a route handler for '/movie.:format' route
func Handler(c *gin.Context) {
	requestType := c.Param("format")
	term := c.Request.PostFormValue("text")

	log.Printf("Movie Query: %s", term)

	movie, err := lookupMovie(term)

	switch requestType {
	case "json":
		if err != nil {
			c.JSON(http.StatusNotFound, gin.H{"Response": err.Error()})
		} else {
			c.IndentedJSON(http.StatusOK, movie)
		}
	case "slack":
		text, err := formatSlackResp(movie)
		if err != nil {
			c.String(http.StatusNotFound, "Not Found")
		}

		c.String(http.StatusOK, text)
	default:
		c.JSON(http.StatusUnsupportedMediaType, nil)
	}
}
開發者ID:ketan-ghumatkar,項目名稱:cowboy,代碼行數:27,代碼來源:movie_lookup.go

示例2: Handler

// Handler is a route handler for '/movie.:format' route
func Handler(c *gin.Context) {
	requestType := c.Param("format")
	text := c.Request.PostFormValue("text")

	operator, circle := parsedReqText(text)
	log.Printf("Recharge Query:: Circle := %s, Operator := %s", circle, operator)

	var list []Plan
	list, err := findPlans(circle, operator)

	switch requestType {
	case "json":
		if err != nil {
			c.JSON(http.StatusNotFound, gin.H{"Response": err.Error()})
		} else {
			c.IndentedJSON(http.StatusOK, list)
		}
	case "slack":
		text, err := formatSlackResp(list)
		if err != nil {
			c.String(http.StatusNotFound, "Not Found")
		}

		c.String(http.StatusOK, text)
	default:
		c.JSON(http.StatusUnsupportedMediaType, nil)
	}
}
開發者ID:ketan-ghumatkar,項目名稱:cowboy,代碼行數:29,代碼來源:recharge.go

示例3: PostsHandler

// PostsHandler is a route handler for '/producthunt/posts.:format' route
func PostsHandler(c *gin.Context) {
	requestType := c.Param("format")
	daysAgo, err := strconv.Atoi(c.Request.PostFormValue("text"))
	if err != nil {
		daysAgo = 0
	}

	log.Printf("Days Ago: %d", daysAgo)

	posts, err := getPosts(daysAgo)

	switch requestType {
	case "json":
		if err != nil {
			c.JSON(http.StatusNotFound, gin.H{"Response": err.Error()})
		} else {
			c.IndentedJSON(http.StatusOK, posts)
		}
	case "slack":
		text, err := formatPostsSlackResp(posts)
		if err != nil {
			c.String(http.StatusNotFound, "Not Found")
		}

		c.String(http.StatusOK, text)
	default:
		c.JSON(http.StatusUnsupportedMediaType, nil)
	}
}
開發者ID:ketan-ghumatkar,項目名稱:cowboy,代碼行數:30,代碼來源:posts.go

示例4: Handler

// Handler is a route handler for '/excuse.:format' route
func Handler(c *gin.Context) {
	requestType := c.Param("format")
	excuse, err := getAnExcuse()

	switch requestType {
	case "json":
		if err != nil {
			c.JSON(http.StatusNotFound, gin.H{"Response": err.Error()})
		} else {
			c.IndentedJSON(http.StatusOK, excuse)
		}
	case "slack":
		if err != nil {
			c.String(http.StatusNotFound, "> I am not feeling well\n")
		}

		c.String(http.StatusOK, "\n> "+excuse.Text+"\n")
	default:
		c.String(http.StatusUnsupportedMediaType, "")
	}
}
開發者ID:ketan-ghumatkar,項目名稱:cowboy,代碼行數:22,代碼來源:excuse.go


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