Open worldadmin opened 4 years ago
Add a method to Context
in file https://github.com/gin-gonic/gin/blob/master/context.go
func (c *Context) Msgpack(code int, obj interface{}) {
c.Render(code, render.MsgPack{Data: obj})
}
then, you can response in msgpack:
func main() {
r := gin.Default()
// gin.H is a shortcut for map[string]interface{}
r.GET("/someMsgpack", func(c *gin.Context) {
c.Msgpack(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK})
})
// Listen and serve on 0.0.0.0:8080
r.Run(":8080")
}
How to set response in msgpack like this https://github.com/gin-gonic/gin#xml-json-yaml-and-protobuf-rendering ?