1. First initialize go mod.
go mod init <file.go>
  1. Install modules
go mod tidy

And you are done.

Reference: StackOverflow