Project Setup
Learn how to set up a Go API.
We'll cover the following
Getting started
It’s critical to have a good project structure. Writing clean code makes it easier to collaborate and update. We’ll ensure that our code is well structured, properly commented on, and easy to understand throughout the development process.
Folder setup
We’ll start by creating a folder. Let’s call our folder "shive." This is going to be our root folder.
In the integrated terminal in our IDE, we’ll type in
go mod init shive-api
to create our mod file. Our mod file is where we store all the packages we make use of.Now let’s set up our
.env
file. It stores our environment variables and constants. To create this, we need to create a file called.env
in the root folder.Let’s add a few constants to our
.env
file. We’ll add our port; we’ll also add our MongoDB connection string from MongoDB Atlas and swap out the<password>
field for our shiveAdmin password. We’ll also add a secret key—we can give it any value we want.
Get hands-on with 1400+ tech skills courses.