diff --git a/api/context.go b/api/context.go index 26e7fb20d7cc3a13c32256fdd7207634522c01d3..637b60a0399d7e764e100264efa25597f2db1201 100644 --- a/api/context.go +++ b/api/context.go @@ -150,7 +150,6 @@ func (ctx apiContext) GetRequestBody(requestStructType reflect.Type) (interface{ return nil, errors.Wrapf(err, "invalid request body") } } - return requestStructValuePtr.Elem().Interface(), nil } @@ -175,6 +174,11 @@ func (ctx *apiContext) applyClaim(name string, valuePtr interface{}) error { } func (ctx *apiContext) setClaim(name string, structType reflect.Type, structValue reflect.Value) error { + if len(ctx.Claim()) == 0 { + ctx.Debugf("NO CLAIM to apply to %s of type (%s)", name, structType.Name()) + return nil + } + for fieldName, claimValue := range ctx.Claim() { if field := structValue.FieldByName(fieldName); field.IsValid() { if err := reflection.SetValue(field, claimValue); err != nil { diff --git a/api/handler.go b/api/handler.go index a25807989c46b56718c26e67185c03e2c0b29681..3432cfb00a18e0d5ba05bf1a9d6530bd5c30dd57 100644 --- a/api/handler.go +++ b/api/handler.go @@ -60,20 +60,6 @@ func NewHandler(fnc interface{}) (handler, error) { h.RequestBodyType = fncType.In(2) } - //if 2 results, first must be response struct or array of response structs that will be marshalled to JSON - if fncType.NumOut() > 1 { - if fncType.Out(0).Kind() == reflect.Slice { - if err := validateStructType(fncType.Out(0).Elem()); err != nil { - return h, errors.Errorf("first result %v is not valid response []struct type", fncType.Out(0)) - } - } else { - if err := validateStructType(fncType.Out(0)); err != nil { - return h, errors.Errorf("first result %v is not valid response struct type", fncType.Out(0)) - } - } - h.ResponseType = fncType.Out(0) - } - //last result must be error if _, ok := reflect.New(fncType.Out(fncType.NumOut() - 1)).Interface().(*error); !ok { return h, errors.Errorf("last result %v is not error type", fncType.Out(fncType.NumOut()-1))