You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
699 B

  1. // Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved.
  2. package container
  3. import (
  4. "errors"
  5. "fmt"
  6. "reflect"
  7. )
  8. // 组件实例
  9. type Instance reflect.Value
  10. var ZeroInstance = Instance(reflect.ValueOf(nil))
  11. // 获取调用器
  12. // 参数
  13. // 1.服务实例
  14. // 返回值:
  15. // 1.调用器
  16. // 2.错误
  17. func (instance Instance) GetCaller(methodName string) (Caller, error) {
  18. if methodName == "" {
  19. return nil, errors.New(fmt.Sprintf("方法名不能为空!"))
  20. }
  21. methodValue := reflect.Value(instance).MethodByName(methodName)
  22. if methodValue == reflect.ValueOf(nil) {
  23. return nil, errors.New(fmt.Sprintf("未找到方法!"))
  24. }
  25. return methodValue.Call, nil
  26. }