
Lesson Description
The "Go Project Setup" Lesson is part of the full, Build a Fullstack App with Vanilla JS and Go course featured in this preview video. Here's what you'd learn in this lesson:
Maximiliano demonstrates how to create a new Go module using the "go mod init" command and explains the basic structure of a Go project. Additionally, Maximiliano discusses the process of adding external dependencies to the project using the go.mod file and the "go get" command.
Transcript from the "Go Project Setup" Lesson
[00:00:00]
>> Maximiliano Firtman: Now it's time to start our project, okay? Before getting into the architecture, I will go back to my project in VS code, okay, this is what I got from GitHub from the URL. It's completely empty, and again, if you open the readme, you go to the top, and you can see, step by step, okay?
[00:00:20]
what they're going to be building and writing, so we need to start by creating a go project. Actually, it's called a go module, in go, we call this module. So the first step will be in this folder, I will open a terminal, so terminal, new terminal, or use the shortcut.
[00:00:38]
And in the terminal we are going to be creating a new module using Go. And for that, we use go mod init, and then we need the name of the project. In Go, we typically name the project with kind of a URL system, even if it's not a valid existent URL.
[00:01:02]
So for example here we can say frontalmasters.com forward slash really neat or movies however, you wanna call that. And if you wanna change that name later it's actually pretty the only thing that is new now is that we do have a go dot mod file. And that go dot mod file is actually saying that's the name of the module, that's all, okay, it's not really a big deal.
[00:01:28]
Remember, if you wanna call it movies, it's okay, it's up to you the name that you will use here, okay, you change that name. The only important part is that later, when we are importing package sheets in Go from one package from another package. We use that full URL, okay, so you can change that later, but have in mind that you also will need to update all your packages, all your import declarations.
[00:01:53]
Well, the next step is to create the main file that typically we call it main.go and, so we create a new file, okay? And that map we find what we call main.go, and here we can start writing our code. And most of the time we have a well, package main and a function, main, func main, that's all, that's we have our Go project the minimum, at least go project ready, okay?
[00:02:29]
But just because we are here, I already mentioned that we are going to be using some external dependencies, some libraries. So let's start adding those libraries, at least the two most important ones that we will use, we can do that later as well every time, actually before using it.
[00:02:46]
And also if you're using BS code, when you try to use the library for the first time. And you didn't include the dependency of the library, BS code will ask you, hey, do you wanna install it, and it will do that for you, but let's do it manually.
[00:02:59]
So again, the readme you have this, snippet to copy and paste if you want, actually, it's not a big deal. But this is the godotdem project, this is the one that will let us use the dotdem files to store, for example, credentials and other information that are secret information.
[00:03:20]
And this one is actually the one that will let us use Postgres in Go, okay? So, I will copy this, and I will paste this in the terminal, and this has just added the two dependencies. You will see that when you go to the go dot mold file that now we have require and we have two dependencies, okay, for now that's all.
[00:03:54]
If this is the first time you're using these two dependencies, your computer is going to download the files as well. If you have already used those dependencies before another project, you won't see the download in part as it happened with my case. I haven't seen any downloading, that's because I already have them in my computer.
[00:04:14]
Go is storing dependencies in some kind of a global space in your user in the operating system. So it's not like Node modules with Node.js that you have the dependencies in your project. So every project has its own dependencies, here no Go is taking those from a global space in your user profile in the operating system.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops