ZhangZhihui's Blog  

The Go language maintainer has no strong convention about structuring a project in Go. However, one layout has emerged over the years: project-layout (https://github.com/golang-standards/project-layout).


If our project is small enough (only a few files), or if our organization has already created its standard, it may not be worth using or migrating to project-layout. Otherwise, it might be worth considering. Let’s look at this layout and see what the main directories are:
/cmd—The main source files. The main.go of a foo application should live in /cmd/foo/main.go.
 /internal—Private code that we don’t want others importing for their applications or libraries.
 /pkg—Public code that we want to expose to others.
 /test—Additional external tests and test data. Unit tests in Go live in the same package as the source files. However, public API tests or integration tests, for example, should live in /test.
 /configs—Configuration files.
 /docs—Design and user documents.
 /examples—Examples for our application and/or a public library.
 /api—API contract files (Swagger, Protocol Buffers, etc.).
 /web—Web application-specific assets (static files, etc.).
 /build—Packaging and continuous integration (CI) files.
 /scripts—Scripts for analysis, installation, and so on.
 /vendor—Application dependencies (for example, Go modules dependencies).
There’s no /src directory like in some other languages. The rationale is that /src is too generic; hence, this layout favors directories such as /cmd, /internal, or /pkg.

 

posted on   ZhangZhihuiAAA  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
 
点击右上角即可分享
微信分享提示