|
|
|
Show HN: A sample project for Golang
|
|
57 points
by shivylp
2763 days ago
|
|
I have been using golang at work and personally for more than 2 years now. A problem i faced when I started and the problem new gophers even today is how to structure the project. Most (if not all) golang tutorials seem to be very simple and do not describe how to structure a large application. Following project is an attempt to Showcase a manageable project layout for services in golang. https://github.com/spy16/droplets This project is far from complete. Would like to hear some feedback from the community before continuing on this. |
|
Every single Go program starts with a simple layout - empty directory and main.go file.
Once you start adding things, you create more .go files in the same folder, and only when it grows bigger you start thinking of moving some abstractions into separate packages.
The key difference with most other languages is that in Go folder means "package", not "namespace for bunch or files". It's a crucial difference that important to keep in mind with Go. And what is (sub)package? When do you need new subpackage? It's just a higher level way to abstract logic or system component - make it more isolated than just concrete type, change the naming and usage API to be more clear and self-sustained.
Before that, you don't have to create new packages (=folders) in Go.
The vast majority of all Go projects will never need `internal` or `cmd` folder, not to mention `pkg` or `web`.
Just start with main.go and let it grow naturally. The simpler and easier your package is, the better.