Migrate to Go Modules
Go provides a new feature called Modules which provides flexibility to manage your project and dependencies with ease. If you are working on Go packages, then you should consider relocating your project to Go Modules.
Anatomy of Modules in Go
Modules are a new way to manage dependencies of your project. Modules enable us to incorporate different versions of…
Imagine you have more than a thousand functions that you need constantly while working on any project. Some of these functions have common behavior. For example,
toLowerCase function transforms case of a
string, so you write them in a single file (probably case.go). There are other functions which do some other operations on
string data type, so you write them in a separate file.
Since you have many files which do something with
string data type, so you created a directory named
string and put all
string related files into it. Finally, you put all of these directories in one parent directory which will be your package. The whole package structure looks like below.
| ├── case.go
| ├── trim.go
| └── misc.go
I will explain thoroughly, how we can import functions and variables from a package and how everything blends together to form a package, but for now, imagine your package as a directory containing
Every Go program must be a part of some package. As discussed in Getting started with Go lesson, a standalone executable Go program must have
package main declaration. If a program is part of the main…