⚠️ This lesson is retired and might contain outdated information.

Initializing a project using Go modules

Chris Biscardi
InstructorChris Biscardi
Share this video with your friends

Social Share Links

Send Tweet

Golang includes the go mod command to initialize a new project. Sometimes that command fails even though it tries to be smart about where to get the name of your module from so we give an example of how to explicitly set the name of your go modules based project.

mkdir my-go-project
cd my-go-project
go mod init github.com/christopherbiscardi/my-go-project

Instructor: [00:00] To initialize a new golang project with Go modules, first we'll create a new directory for our new project.

[00:10] Now that we're in our new project directory, we can run go mod init. Go mod init tries to be smart about how it creates your new Go modules project. You can see here that we are outside our GOPATH and we don't have any import comments in our project, because we don't even have any Go files yet.

[00:29] To tell Go modules what the name of our module is, we use go mod init, with the fully qualified path to our module. We can see that go mod has now succeeded. Also note that we have a new file, called go.mod, that includes our module and the Go version we used. When we add imports to our Go code later, they'll also be added to this file.