From 24cea058880f6fb953c4a25816ef60ebbd10838b Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 30 Mar 2021 15:07:39 +0800 Subject: [PATCH] 1. add ShouldBindMsgPack; 2. seriallize the given struct as MsgPack into the response body. --- context.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/context.go b/context.go index 3d6b56d6..598dda80 100644 --- a/context.go +++ b/context.go @@ -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{}) {