有以下代码:用户模型.gotype 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.gotype PostModel struct{title, description}func GetAll() map[string]PostModel {/* like in UserModel */}用户控制器.gotype ControllerUser struct{}func GetAll()map[string]UserModel { rertun UserModel.GetAll() } PostController.gotype ControllerPost struct{}func GetAll()map[string]PostModel { rertun PostModel.GetAll() }我尝试动态检测必要的控制器:main.govar currentController = Intfcswitch entity { "user" : currentController = UserController.ControllerUser{} "post" : currentController = PostController.ControllerPost{}}currentController.GetAll()为此,我需要一个通用接口接口.gotype Intfc interface { ShowAll() ???}函数(在接口中)返回什么类型的返回数据?
1 回答

互换的青春
TA贡献1797条经验 获得超6个赞
我做到了!@leafbebop、@Flimzy 和其他人期待https://github.com/arturturundaev/simpleCRUDproject
- 1 回答
- 0 关注
- 183 浏览
添加回答
举报
0/150
提交
取消