// Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved.
|
|
|
|
package container
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"reflect"
|
|
)
|
|
|
|
// 组件实例
|
|
type Instance reflect.Value
|
|
|
|
var ZeroInstance = Instance(reflect.ValueOf(nil))
|
|
|
|
// 获取调用器
|
|
// 参数
|
|
// 1.服务实例
|
|
// 返回值:
|
|
// 1.调用器
|
|
// 2.错误
|
|
func (instance Instance) GetCaller(methodName string) (Caller, error) {
|
|
if methodName == "" {
|
|
return nil, errors.New(fmt.Sprintf("方法名不能为空!"))
|
|
}
|
|
methodValue := reflect.Value(instance).MethodByName(methodName)
|
|
if methodValue == reflect.ValueOf(nil) {
|
|
return nil, errors.New(fmt.Sprintf("未找到方法!"))
|
|
}
|
|
return methodValue.Call, nil
|
|
}
|