1. add ShouldBindMsgPack; 2. seriallize the given struct as MsgPack into the response body.

This commit is contained in:
unknown 2021-03-30 15:07:39 +08:00
parent a331dc6a31
commit 24cea05888
1 changed files with 11 additions and 0 deletions

View File

@ -668,6 +668,11 @@ func (c *Context) ShouldBindJSON(obj interface{}) error {
return c.ShouldBindWith(obj, binding.JSON)
}
// ShouldBindMsgPack is a shortcut for c.ShouldBindWith(obj, binding.MsgPack).
func (c *Context) ShouldBindMsgPack(obj interface{}) error {
return c.ShouldBindWith(obj, binding.MsgPack)
}
// ShouldBindXML is a shortcut for c.ShouldBindWith(obj, binding.XML).
func (c *Context) ShouldBindXML(obj interface{}) error {
return c.ShouldBindWith(obj, binding.XML)
@ -908,6 +913,12 @@ func (c *Context) JSON(code int, obj interface{}) {
c.Render(code, render.JSON{Data: obj})
}
// MsgPack serializes the given struct as MsgPack into the response body.
// It also sets the Content-Type as "application/msgpack".
func (c *Context) MsgPack(code int, obj interface{}) {
c.Render(code, render.MsgPack{Data: obj})
}
// AsciiJSON serializes the given struct as JSON into the response body with unicode to ASCII string.
// It also sets the Content-Type as "application/json".
func (c *Context) AsciiJSON(code int, obj interface{}) {