package check
import "fmt"
type ICheck interface {
check(params map[string]string)
}
type Checker struct {
TileCompleteCheck
}
type TileCompleteCheck struct {
}
func (e *TileCompleteCheck) Check(params map[string]string) {
for k, v := range params {
fmt.Println(k, v)
}
}
package main
import (
"fmt"
"geotool/check"
"reflect"
)
func main() {
fmt.Println(123)
c := check.Checker{}
// 定义要传递的参数
params := make(map[string]string)
params["key1"] = "value1"
params["key2"] = "value2"
val := reflect.ValueOf(&c)
fieldVal := val.Elem().FieldByName("TileCompleteCheck")
method := fieldVal.Addr().MethodByName("Check")
// 使用 reflect.ValueOf 创建一个参数的 reflect.Value
method.Call([]reflect.Value{reflect.ValueOf(params)})
}
package check
type BaseCheck struct {
}
func (e *BaseCheck) Check(params map[string]string) {
for k, v := range params {
fmt.Println(k, v)
}
}
package main
import (
"fmt"
"geotool/check"
"reflect"
)
func main() {
fmt.Println(123)
baseCheck := check.BaseCheck{}
// 定义要传递的参数
params := make(map[string]string)
params["key1"] = "value1"
params["key2"] = "value2"
baseCheckVal := reflect.ValueOf(&baseCheck)
method := baseCheckVal.MethodByName("Check")
// 使用 reflect.ValueOf 创建一个参数的 reflect.Value
method.Call([]reflect.Value{reflect.ValueOf(params)})
}
网友评论