Skip to content
Snippets Groups Projects
Commit 4c5df47f authored by Jan Semmelink's avatar Jan Semmelink
Browse files

Remove restrictions on handler response type - any type that can marshal to JSON is ok.

parent 745750a4
Branches
Tags
No related merge requests found
......@@ -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 {
......
......@@ -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))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment