This commit is contained in:
crusader 2018-04-12 16:13:23 +09:00
parent 7dfdba6cf7
commit 9fb5b13f48
2 changed files with 45 additions and 0 deletions

View File

@ -3,4 +3,5 @@ package registry
type RESTInvoker interface {
HasMethod(method string) bool
Invoke(method string, params []string, leadingParams ...interface{}) (result interface{}, err error)
InvokeWithBytes(method string, params [][]byte, leadingParams ...interface{}) (result interface{}, err error)
}

View File

@ -1,7 +1,9 @@
package registry
import (
"fmt"
"reflect"
"strconv"
cuej "git.loafle.net/commons/util-go/encoding/json"
cus "git.loafle.net/commons/util-go/service"
@ -87,6 +89,48 @@ func (rr *restRegistry) HasMethod(method string) bool {
return false
}
// Invoke execute a method.
//
// Codecs are defined to process a given serialization scheme, e.g., JSON or
// XML. A codec is chosen based on the "Content-Type" header from the request,
// excluding the charset definition.
func (rr *restRegistry) InvokeWithBytes(method string, params [][]byte, leadingParams ...interface{}) (result interface{}, err error) {
_, methodSpec, errGet := rr.serviceRegistry.Get(method)
if nil != errGet {
return nil, errGet
}
// Decode the args.
pValues, pInstances := methodSpec.ParamValues()
lParamLen := 0
if nil != leadingParams {
lParamLen = len(leadingParams)
}
var _params []string
if nil != pInstances && 0 < len(pInstances) {
if len(pInstances) != (len(params) + lParamLen) {
return nil, fmt.Errorf("count of parameter is not same method[%d] and %d", len(pInstances), (len(params) + lParamLen))
}
for indexC := 0; indexC < len(params); indexC++ {
if pValues[indexC+lParamLen].Type().Kind() != reflect.String {
_params = append(_params, string(params[indexC]))
continue
}
ts, err := strconv.Unquote(string(params[indexC]))
if nil != err {
return nil, err
}
_params = append(_params, ts)
}
}
return rr.Invoke(method, _params, leadingParams...)
}
// Invoke execute a method.
//
// Codecs are defined to process a given serialization scheme, e.g., JSON or