duanhu7390
2019-05-01 00:16 阅读 828
已采纳

go mod子目录结构

I'm using the following struct on my project, but it feels hacky

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

Is there a way to organize it like that?

App
├── go.mod
└── src
    ├── app.go
    └── foo
    |    └── foo.go
    └── bar
        └── bar.go
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    doujia7517 doujia7517 2019-05-01 01:50

    You could just move the app.go file into the src directory.

    However, it's generally ill-advised to have an src folder in a Go project. I recommend you take a look here for recommendations re: project structure.

    点赞 评论 复制链接分享
  • drwkqwa82140 drwkqwa82140 2019-05-02 03:58

    I like the following structure

    App
    ├── makefile
    ├── go.mod
    ├── httpd <- Entrypoint is here - CLI or Http Server
    |   └── main.go
    └── platform <- Project specific dependencies that are not shared between projects
    

    e.g

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

    I describe it here on YouTube https://youtu.be/zeme_TmXyBk

    点赞 评论 复制链接分享

相关推荐