av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

創(chuàng)新互聯(lián)Gin教程:GinXML/JSON/YAML/ProtoBuf渲染

func main() {
	r := gin.Default()

	// gin.H 是 map[string]interface{} 的一種快捷方式
	r.GET("/someJSON", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK})
	})

	r.GET("/moreJSON", func(c *gin.Context) {
		// 你也可以使用一個(gè)結(jié)構(gòu)體
		var msg struct {
			Name    string `json:"user"`
			Message string
			Number  int
		}
		msg.Name = "Lena"
		msg.Message = "hey"
		msg.Number = 123
		// 注意 msg.Name 在 JSON 中變成了 "user"
		// 將輸出:{"user": "Lena", "Message": "hey", "Number": 123}
		c.JSON(http.StatusOK, msg)
	})

	r.GET("/someXML", func(c *gin.Context) {
		c.XML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK})
	})

	r.GET("/someYAML", func(c *gin.Context) {
		c.YAML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK})
	})

	r.GET("/someProtoBuf", func(c *gin.Context) {
		reps := []int64{int64(1), int64(2)}
		label := "test"
		// protobuf 的具體定義寫(xiě)在 testdata/protoexample 文件中。
		data := &protoexample.Test{
			Label: &label,
			Reps:  reps,
		}
		// 請(qǐng)注意,數(shù)據(jù)在響應(yīng)中變?yōu)槎M(jìn)制數(shù)據(jù)
		// 將輸出被 protoexample.Test protobuf 序列化了的數(shù)據(jù)
		c.ProtoBuf(http.StatusOK, data)
	})

	// 監(jiān)聽(tīng)并在 0.0.0.0:8080 上啟動(dòng)服務(wù)
	r.Run(":8080")
}

本文名稱:創(chuàng)新互聯(lián)Gin教程:GinXML/JSON/YAML/ProtoBuf渲染
當(dāng)前鏈接:http://uogjgqi.cn/article/codidde.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流