为了账号安全,请及时绑定邮箱和手机立即绑定

接口中的动态返回类型

接口中的动态返回类型

Go
慕哥6287543 2022-04-26 15:28:16
有以下代码:用户模型.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


查看完整回答
反对 回复 2022-04-26
  • 1 回答
  • 0 关注
  • 183 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号