有以下代码:
用户模型.go
type UserModel struct{login, password}
var EntityArr = map[string]UserModel{}
func GetAll() map[string]UserModel {
uuidString := uuid.New().String()
user := Entity{Login: "myLogin", Password: "MyPassword"}
EntityArr[uuidString] = user
return EntityArr
}
PostModel.go
type PostModel struct{title, description}
func GetAll() map[string]PostModel {/* like in UserModel */}
用户控制器.go
type ControllerUser struct{}
func GetAll()map[string]UserModel { rertun UserModel.GetAll() }
PostController.go
type ControllerPost struct{}
func GetAll()map[string]PostModel { rertun PostModel.GetAll() }
我尝试动态检测必要的控制器:
main.go
var currentController = Intfc
switch entity {
"user" : currentController = UserController.ControllerUser{}
"post" : currentController = PostController.ControllerPost{}
}
currentController.GetAll()
为此,我需要一个通用接口
接口.go
type Intfc interface {
ShowAll() ???
}
函数(在接口中)返回什么类型的返回数据?
互换的青春
相关分类