The purpose of this article is demonstrating how easy is to migrate our old projects with vendors directory to a new one that makes use of go mods.

I’m not going to enum the benefits of using go modules versus using dependencies management tool because there are several posts about this on the Internet. On the other hand, I will guide you on how to migrate your project

Checkout latest golang version

You could ask me, why the last? Because if we all are Software enthusiast we should desire to test the latests technologies! (By the way, you could use a golang 1.11.X, but you should wonder why not using the latest available version…)

So go here, and download the distribution for your OS.

Find a project to be migrated

In this article, I will migrate a personal project in which I worked a few months ago. In this project, I made use of Glide for managing the dependencies. You could do the same for any of your projects.

Don’t worry about what mollydb does, because we only need to understand how to migrate an existing project.

Adapt the project structure

This project is structured with a src folder that contains a subfolder mollydb and inside of this one a vendor directory with the dependencies.

src > mollydb > vendors

It was the only way I found for creating projects not dependent on my global GO path…

We will remove the vendors directory and move the content in src/mollydb to the root of the project.

Them we can run command

Go is smart enough and It will fill the go.mod file with the dependencies in glide.lock.

go: creating new go.mod: module mollydb

go: copying requirements from glide.lock

And the content of go.mod will look like this

Anyway, if we remove the glide configuration files and the created go.mod and run below commands.

The go.mod will be generated because go mod inspects our go files.

We just need to run the below command to verify that the project works as It used to do.

go run main.go

That’s all folks!

Our project was migrated!!