cloud-go/gin/2-template
2022-06-20 09:29:22 +08:00
..
assets gin 2022-06-20 09:29:22 +08:00
templates gin 2022-06-20 09:29:22 +08:00
.air.toml gin 2022-06-20 09:29:22 +08:00
.gitignore gin 2022-06-20 09:29:22 +08:00
go.mod gin 2022-06-20 09:29:22 +08:00
go.sum gin 2022-06-20 09:29:22 +08:00
main.go gin 2022-06-20 09:29:22 +08:00
README.md gin 2022-06-20 09:29:22 +08:00

JSON渲染

r.GET("/moreJSON", func(c *gin.Context) {
		// 方法二:使用结构体
		var msg struct {
			Name    string `json:"user"`
			Message string
			Age     int
		}
		msg.Name = "小王子"
		msg.Message = "Hello world!"
		msg.Age = 18
		c.JSON(http.StatusOK, msg)
	})

Yaml

    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})
	})