Switching to Go Modules - bye GOPATH and Godep

Go modules! Finally you don’t have to place your code into the directory structure imposed by GOPATH! Also, you don’t need to set up external tooling, such as Godep, to manage your project’s dependencies.

All you need is to use Go in the version 1.11+ and you’re set.

Well, not quite.

Before you can start enjoying modules, you need to make the switch to them, or init your fresh new project to use them. Here’s how:

Apply it to an old project

You have an existing project, and want to start using go modules? Run the following command, and you’re almost done:

go mod init

The last argument, is the importable path to the directory you’re working from.

If you are already using godep, you won’t need to do anything. The versions you specified prior, are copied over from your Godep files. All that’s left to do, is to delete the old Godeps.* files once the command is done.

When you’re starting from scratch

If you haven’t been using Godep on an old project, or are starting a new Go project and would like to use modules, all you need is a single command.

After the mod init command like above, you can use go get to add dependencies to the project, and have the module remember their exact version.

Additional Resources

Want to create better Django apps?

Subscribe for articles about building for the web with Django!

    (About the content, privacy, analytics and revocation).

    We won't send you spam. Unsubscribe at any time.