Member-only story
How to Structure your next Golang App with Go Mod and Subfolders
Coding your next Golang Project using Go Mod and Subfolders.
Maybe you are someone looking to start building a project in Golang. First starting out, you may never consider the structure of the codebase and it is easy to leave out or forget to structure your project for the future.
Here are a few tips for organizing your own project and getting your GoLang codebase to be more scalable for the future.
How NOT to structure your APP in Golang.
I’ve set up a simple Golang app like “Hello world” to demonstrate.
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
This may seem correct, however, you really should have started with Go Mod.
The real reason not using Go Mod is a bad idea is because you will not be able to link packages from outside the project root or access sub-packages easily.
In order to keep packages contained within subfolders, you will need to import each module for the Go Compiler to be able to access them directly.
Furthermore, Go Mod Relies on the ability to manage packages as dependencies. We will demonstrate this later on. Let’s first dive into the benefits of…