1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-09 04:51:56 +00:00

add context.Protobuf, MsgPack, ReadProtobuf, ReadMsgPack methods

Former-commit-id: 39d547ecfb1516505a1eb76a12a1f6e9e4111962
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-04-08 16:48:22 +03:00
parent ee4213f72d
commit 837787104b
16 changed files with 215 additions and 40 deletions

View File

@@ -7,6 +7,8 @@ import (
"strings"
"github.com/kataras/iris/v12/context"
"github.com/golang/protobuf/proto"
)
// binding contains the Dependency and the Input, it's the result of a function or struct + dependencies.
@@ -344,6 +346,14 @@ func payloadBinding(index int, typ reflect.Type) *binding {
err = ctx.ReadForm(ptr)
case context.ContentJSONHeaderValue:
err = ctx.ReadJSON(ptr)
case context.ContentProtobufHeaderValue:
if msg, ok := ptr.(proto.Message); ok {
err = ctx.ReadProtobuf(msg)
} else {
err = context.ErrContentNotSupported
}
case context.ContentMsgPackHeaderValue, context.ContentMsgPack2HeaderValue:
err = ctx.ReadMsgPack(ptr)
default:
if ctx.Request().URL.RawQuery != "" {
// try read from query.