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 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题