Hello everyone. I’ve been learning golang over the past few weeks (mainly using the Go playground), but now I find myself wondering how to properly structure, or organize, a go application. I’ve read quite a few posts on this topic and what I’m using right now is this
project_directory
|--bin
|--pkg
`--src
`--github.com
My GOPATH is set to my “project_directory”. Now this means that every folder under github.com/ is basically a repository and therefore under version control on GitHub. I come from the Java world, so it’s been hard for me to grasp the concept that my project directory itself isn’t under version control.
So with that in mind, I made a couple of Google search to find out about the Go modules with the go.mod file which would allow me to structure an app like so (if I understood what I read correctly):
project_directory
|--go.mod
`--src
|--module1
`--module2
My understanding here is that this would allow me to have the project directory with the ‘go.mod’ file under version control as well as the empty src directory. Empty src because go will fetch the modules from the go.mod file.
So this is my understanding of it, again I come from Java/Maven world so I might be completely off the rails here.
I know there isn’t any agreed upon standard for an application structure, I’ve seen quite a few suggestions out there that seems to be popular. So my questions (finally) are these:
- As it is not officially rolled out should I keep using the GOPATH method or can I safely use the go.mod method
- Regarding the go.mod way to do things, is there any way you guys think is more appropriate to structure an application that’ll end up being a docker image.
Thank you for all your help