feature: add http middleware capability #18

Merged
xdrm-brackets merged 5 commits from feature/middleware into 0.3.0 2021-04-18 16:08:12 +00:00
1 changed files with 24 additions and 0 deletions
Showing only changes of commit a693bbbf9b - Show all commits

View File

@ -2,6 +2,7 @@ package dynfunc
import ( import (
"fmt" "fmt"
"log"
"reflect" "reflect"
"git.xdrm.io/go/aicra/api" "git.xdrm.io/go/aicra/api"
@ -70,6 +71,29 @@ func (h *Handler) Handle(data map[string]interface{}) (map[string]interface{}, a
if !inData { if !inData {
continue continue
} }
var refvalue = reflect.ValueOf(value)
// T to pointer of T
if field.Kind() == reflect.Ptr {
var ptrType = field.Type().Elem()
if !refvalue.Type().ConvertibleTo(ptrType) {
log.Printf("Cannot convert %v into %v", refvalue.Type(), ptrType)
return nil, api.ErrUncallableService
}
ptr := reflect.New(ptrType)
ptr.Elem().Set(reflect.ValueOf(value).Convert(ptrType))
field.Set(ptr)
continue
}
if !reflect.ValueOf(value).Type().ConvertibleTo(field.Type()) {
log.Printf("Cannot convert %v into %v", reflect.ValueOf(value).Type(), field.Type())
return nil, api.ErrUncallableService
}
field.Set(reflect.ValueOf(value).Convert(field.Type())) field.Set(reflect.ValueOf(value).Convert(field.Type()))
} }
callArgs = append(callArgs, callStruct) callArgs = append(callArgs, callStruct)