PHP 版本这样:
public function factory ($string ) {
reutnr new $string
}
而 GO 版本还得预定义,我是这样
func GetInstance (str string ) reflect.Value {
var typeRegistry = make (map[string]reflect.Value )
typeRegistry["xxx"] = reflect.ValueOf (&XXX{})
// ... 有多少这样就有预定义多少
return typeRegistry[str].MethodByName ("GetData")
}