Fix go: go.mod file not found in current directory or any parent directory; see 'go help modules'

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

And you are done.

Reference: StackOverflow