1. First initialize go mod.
go mod init <file.go>

[–more–]

  1. Install modules
go mod tidy

And you are done.

Reference: StackOverflow