有以下代碼:用戶模型.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() }我嘗試動態(tài)檢測必要的控制器:main.govar currentController = Intfcswitch entity { "user" : currentController = UserController.ControllerUser{} "post" : currentController = PostController.ControllerPost{}}currentController.GetAll()為此,我需要一個通用接口接口.gotype Intfc interface { ShowAll() ???}函數(shù)(在接口中)返回什么類型的返回數(shù)據(jù)?
1 回答

互換的青春
TA貢獻1797條經驗 獲得超6個贊
我做到了!@leafbebop、@Flimzy 和其他人期待https://github.com/arturturundaev/simpleCRUDproject
- 1 回答
- 0 關注
- 176 瀏覽
添加回答
舉報
0/150
提交
取消