ing
This commit is contained in:
parent
7dfdba6cf7
commit
9fb5b13f48
|
@ -3,4 +3,5 @@ package registry
|
||||||
type RESTInvoker interface {
|
type RESTInvoker interface {
|
||||||
HasMethod(method string) bool
|
HasMethod(method string) bool
|
||||||
Invoke(method string, params []string, leadingParams ...interface{}) (result interface{}, err error)
|
Invoke(method string, params []string, leadingParams ...interface{}) (result interface{}, err error)
|
||||||
|
InvokeWithBytes(method string, params [][]byte, leadingParams ...interface{}) (result interface{}, err error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package registry
|
package registry
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
cuej "git.loafle.net/commons/util-go/encoding/json"
|
cuej "git.loafle.net/commons/util-go/encoding/json"
|
||||||
cus "git.loafle.net/commons/util-go/service"
|
cus "git.loafle.net/commons/util-go/service"
|
||||||
|
@ -87,6 +89,48 @@ func (rr *restRegistry) HasMethod(method string) bool {
|
||||||
return false
|
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.
|
// Invoke execute a method.
|
||||||
//
|
//
|
||||||
// Codecs are defined to process a given serialization scheme, e.g., JSON or
|
// Codecs are defined to process a given serialization scheme, e.g., JSON or
|
||||||
|
|
Loading…
Reference in New Issue
Block a user