go: cannot find main module, but found .git config to create a module there, run: go mod

go: cannot find main module, but found .git/config to create a module there, run: go mod

This problem occurred in a monorepo opened in VSCode. The repo has many services placed in isolated directories with respective go.mod files.

I realized from various sources that the problem is from two places:

  1. Move the mono repo under $GOPATH/src.
  2. The ~/.zshrc or ~/.bashrc must be as follows:
    export GOPATH=$HOME/go/
    export GOROOT=/usr/local/go
    
    export PATH="$GOROOT/bin:$PATH"
    export PATH="$PATH:$GOPATH/bin"
    

Do not add any other variable that affects gopls such as GO111MODULE=on.

Written with StackEdit.

References

VSCode Plugins for Golang Development

  1. Rich Go language support for Visual Studio Code
  2. Theme: Dark Knight: A simple dark theme for Golang projects
  3. Git Blame & Git History
  4. Postfix templates for Golang
  5. Adds go to implementation on context menu
  6. All-language autocompleter — TabNine uses machine learning to help you write code faster.

This is a minimal list of Go development extensions in my opinion.

Top 5 VSCode Extensions for Vim Lovers

Vim Extensions

  • vscodevim: Vim emulation for Visual Studio Code
  • Better Align (: + = in visual mode)

Language Specific Extensions

C/C++

  • C/C++ IntelliSense, debugging, and code browsing.
  • Better C++: better-cpp-syntax

Golang

  • Go Microsoft
  • Go Group Imports
  • Go Critic

Python

  • Python Microsoft
  • Python Extension Pack

Ruby

  • Ruby for Visual Studio Code
  • Rubocop
  • Ruby Solargraph

Themes

  • Github Plus
  • Winter Is Coming (Light & Dark)