Project Layout

Organizing and Navigating Through Your Codebase

We now have our database setup and running in a reproducible container. Time to head to our IDE -- GoLand of course -- and start a project for this sample application.

Let's start by creating a New Project in GoLand.

goland_1

Next, provide a project name. I will go for go-gin-bookstore, and click Create.

goland_2

Once you have successfully initialized the project, create two folders in the project root.

  • core - Contains the core business logic of the application.
  • models - Contains database models.

goland_3

Go Dependencies

Next, we need to add the dependencies which are required for the application to run properly: Gin, GORM, and more.

I highly recommend installing the dependencies from go.mod file which you can find from the source code available in GitHub.

go_mod

To install the packages specified in the go.mod file in a Go project, you would typically use the go mod tidy command.

If you're not interested in typing, then GoLand will help you to automatically download the packages.

To configure project settings, select GoLand | Settings on macOS or File | Settings on Windows and Linux from the main menu.

In the Go menu, navigate to the Go Modules.

go_auto_download

Alternatively, while in the go.mod file, you can hover over the names of the missing packages highlighted in red. This action will trigger a prompt to install dependencies, or you can utilize the keyboard shortcut Alt+Enter.

go_missing_dependencies