⚠️ 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
Published 5 years ago
Updated 2 years ago

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.

Erkan Buelbuel
Erkan Buelbuel
~ 4 years ago

I don't like go :/ If typescript compiled, go would be totally superfluous.

Joe
Joe
~ 4 years ago

What shell extension are you using to get the nice filename and line numbers on your cat command?

Chris Biscardi
Chris Biscardiinstructor
~ 4 years ago

What shell extension are you using to get the nice filename and line numbers on your cat command?

It's a tool called bat that replaces cat: https://github.com/sharkdp/bat I have alias cat=bat in my shell profile so whenever I type cat its using bat.

Joe
Joe
~ 4 years ago

It's a tool called bat that replaces cat: https://github.com/sharkdp/bat

Fantastic, thanks Chris.

Markdown supported.
Become a member to join the discussionEnroll Today