电商网站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

相关文章
相关标签/搜索