douqi3064 2017-04-08 15:05
浏览 63
已采纳

同一项目在不同文件夹中的相同软件包名称

I'm working on a big project which will likely end up containing tens of thousands of line of code, for the current structure I do like this:

main.go
controllers/NAME.go
models/NAME.go

The problem with that is that the controllers and models directory contains a lot of files, all using package controllers and package models. I was therefore thinking about splitting it up like this:

main.go
controllers/user/NAME.go
models/user/NAME.go

Where the user files in the controllers package might contain files like routes.go, profile.go, etc.

Now, I read that it's bad practice to name packages like controllersUser or controllers_user, but I worry it might be a bad idea to name both as package user since they're a part of the same project (even if they're located in different directories).

What kind of naming structure would you recommend given my situation?

I realize that the files located in controllers/user will not be able to interact with models/user even through they share the same package user name (unless I import of course), and I also know that I can easy import both as userControllers "controllers/user" and userModels "models/user", but I wonder if it's a bad practice to do like this?

  • 写回答

1条回答 默认 最新

  • dongyong1942 2017-04-08 15:17
    关注

    I suggest you read style guideline for Go packages. It's a fantastic read and contains the best advice I found on the subject when it comes to project layout in Go. I'm having hard times suggesting you a naming for your specific case though because it depends too much on the kind of functionality your system has. Sometimes, I think of it as a "package per part of the application". But I understand my description may result too personal and not very helpful.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度