2017-10-14 16:02



I'm just writing some project that is separated into 3 parts: API written in Golang, mongoDB and android client. And as above I thought it would be good to create directives. But when it's not good practice for golang github projects: for structure like this:

├── API
│   ├── scripts
│   └── src
│       └── some_go_file.go
├── DB
│   ├── db_scripts
│   └── data
└── AndroidDirectory

Any idea how this structure should look like? Should I use separate repos or maybe should I leave each component on separate branch ?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dqw70970 dqw70970 4年前

    There is no particular layout imposed on Go projects on github, save that it would be nice to make it go gettable by having a main package with some go files at the top level. See the instructions here, but bear in mind it starts by talking about workspaces, not apps if you scroll up.

    To compile and run a simple program, first choose a package path (we'll use and create a corresponding package directory inside your workspace:

    $ mkdir $GOPATH/src/ Next, create a file named hello.go inside that directory, containing the following Go code.

    So that's the only bit I'd change - put at least one go file at the top level, you can then have your other packages below that in whatever structure you wish (it's fine to use a src dir if you wish for most packages).

    Use a separate repo for the Android project, because it's unlikely to use the same code (presumably it'll use the API over the network, and will not use mongodb for example directly).

    That leaves your api project and mongodb. As the db data and any scripts are likely related to the api server anyway and will evolve with it, I'd put them as a subdirectory of your project as you have shown.

    点赞 评论 复制链接分享