1 Star 2 Fork 3

kristas/booting-go

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
reflect_x.go 815 Bytes
Copy Edit Raw Blame History
kristas authored 2021-04-09 18:51 . feat: refactor processor and db
package reflectx
import (
"reflect"
)
func WalkStructField(st interface{}, f func(field reflect.StructField, value reflect.Value)) {
t := reflect.TypeOf(st).Elem()
v := reflect.ValueOf(st).Elem()
for i := 0; i < v.NumField(); i++ {
if !v.Field(i).CanSet() {
continue
}
f(t.Field(i), v.Field(i))
}
}
func TryCallMethod(b interface{}, methodName string, args ...interface{}) []reflect.Value {
inputs := make([]reflect.Value, len(args))
for i := range args {
inputs[i] = reflect.ValueOf(args[i])
}
handleMethod := reflect.ValueOf(b).MethodByName(methodName)
if handleMethod.IsValid() {
values := handleMethod.Call(inputs)
return values
}
return nil
}
func IsImplement(child interface{},parent interface{}) bool {
return reflect.TypeOf(child).Implements(reflect.TypeOf(parent).Elem())
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kristas/booting-go.git
git@gitee.com:kristas/booting-go.git
kristas
booting-go
booting-go
v1.1.6

Search