電商網站opencart大流量接口的golang遷移:使用iris+gorm

1.選型
1.1 web框架:iris。結構合理,示例多,文檔豐富。
1.2 orm:gorm。model struct 生成使用xorm。
目前比較看好的還有https://github.com/facebook/ent,就是暫時還不完善。git

2.設計具體的代碼結構
image.pnggithub

3.代碼分層
image.png
遵循CQRS原則,repo負責query,cmd移到下層的models中去。web

4.實現商品詳情接口
4.1 api/main.go
image.pngapi

4.2 api/routes/routes.go
image.png框架

4.3 api/controllers/product/view.go
image.pngspa

4.4 v2/service/product.go
image.png設計

4.5 v2/repo/product.go
image.png3d

4.6 v2/models/product.go
image.pngorm

5.運行效果
image.pngblog

相關文章
相關標籤/搜索