登录
首页 >  Golang >  Go问答

go mod子目录结构

来源:stackoverflow

时间:2024-03-22 22:27:29 232浏览 收藏

在使用 go mod 管理项目结构时,将 app.go 文件放置在 src 目录下是不可取的。建议遵循以下结构: app ├── go.mod ├── makefile ├── httpd | └── main.go └── platform └── user └── user.go

问题内容

我在我的项目中使用以下结构,但感觉很hacky

app
├── go.mod
├── app.go
└── src
    └── foo
    |    └── foo.go
    └── bar
        └── bar.go

有没有办法这样组织它?

App
├── go.mod
└── src
    ├── app.go
    └── foo
    |    └── foo.go
    └── bar
        └── bar.go

解决方案


您可以将 app.go 文件移动到 src 目录中。

但是,在 go 项目中拥有 src 文件夹通常是不明智的。我建议你看看 here 的建议:项目结构。

我喜欢下面的结构

app
├── makefile
├── go.mod
├── httpd <- entrypoint is here - cli or http server
|   └── main.go
└── platform <- project specific dependencies that are not shared between projects

例如

App
├── makefile
├── go.mod
├── httpd
|   └── handlers
|   |    └── hello-world_get.go
|   |    └── hello-world_get_test.go
|   └── main.go
└── platform
    └── user
        └── user.go
        └── user_test.go

我在 youtube 上描述了它 https://youtu.be/zeme_TmXyBk

好了,本文到此结束,带大家了解了《go mod子目录结构》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>