From 4dc9902a970f3dc9595bbe94f7fd27f509553744 Mon Sep 17 00:00:00 2001 From: thinkerou Date: Sun, 3 May 2020 23:44:50 +0800 Subject: [PATCH] Update context.go --- context.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/context.go b/context.go index c56d755c..6d8d7b7f 100644 --- a/context.go +++ b/context.go @@ -36,7 +36,8 @@ const ( MIMEYAML = binding.MIMEYAML ) -const bodyBytesKey = "_gin-gonic/gin/bodybyteskey" +// BodyBytesKey indicates a default body bind key. +const BodyBytesKey = "_gin-gonic/gin/bodybyteskey" const abortIndex int8 = math.MaxInt8 / 2 @@ -687,7 +688,7 @@ func (c *Context) ShouldBindWith(obj interface{}, b binding.Binding) error { // ShouldBindWith for better performance if you need to call only once. func (c *Context) ShouldBindBodyWith(obj interface{}, bb binding.BindingBody) (err error) { var body []byte - if cb, ok := c.Get(bodyBytesKey); ok { + if cb, ok := c.Get(BodyBytesKey); ok { if cbb, ok := cb.([]byte); ok { body = cbb } @@ -697,7 +698,7 @@ func (c *Context) ShouldBindBodyWith(obj interface{}, bb binding.BindingBody) (e if err != nil { return err } - c.Set(bodyBytesKey, body) + c.Set(BodyBytesKey, body) } return bb.BindBody(body, obj) }