12345678910111213141516171819202122232425262728293031 |
- package util
- import (
- "fmt"
- "reflect"
- "unicode"
- "unicode/utf8"
- )
- func CallHandlerFunc(foo reflect.Method, args []reflect.Value) (retValue any, retErr error) {
- defer func() {
- if err := recover(); err != nil {
- fmt.Println(fmt.Sprintf("CallHandlerFunc: %v", err))
- retValue = nil
- retErr = fmt.Errorf("CallHandlerFunc: call method pkg:%s method:%s err:%v", foo.PkgPath, foo.Name, err)
- }
- }()
- if ret := foo.Func.Call(args); len(ret) > 0 {
- var err error = nil
- if r1 := ret[1].Interface(); r1 != nil {
- err = r1.(error)
- }
- return ret[0].Interface(), err
- }
- return nil, fmt.Errorf("CallHandlerFunc: call method pkg:%s method:%s", foo.PkgPath, foo.Name)
- }
- func IsExported(name string) bool {
- w, _ := utf8.DecodeRuneInString(name)
- return unicode.IsUpper(w)
- }
|