This article is a memorandum for Go beginners.
OS: Mac Catalina Shell: Zsh
brew install go
go version
#Output result example) go version go1.15.2 darwin/amd64
go env GOROOT
#Output result example)/usr/local/Cellar/go/1.15.2/libexec
go env GOPATH
#Output result example)/Users/Username/go
ls $(go env GOPATH)
#Output result example) ls: /Users/Username/go: No such file or directory
$ GOPATH directory does not exist yet
when the package installation is not completed.go get github.com/motemen/gore/cmd/gore
ls $(go env GOPATH)
#Output result) bin/ src/
bin /
, and source code is stored in src /
.vim ~/.zshrc
Add the following contents to the end of ~ / .zshrc
~/.zshrc
"Golang path settings
export GOPATH=$(go env GOPATH)
export PATH=$PATH:$GOPATH/bin
Reload ~ / .zshrc
after saving and closing
source ~/.zshrc
gore can execute go interactively like ruby's irb
gore -autoimport
gore>
gore> fmt.Println(Hello World)
Hello World
12
<nil>
↑ 12 bytes are output, meaning that there was no error End with ctrl + d
Allow for code completion, output highlighting, API documentation, etc.
go get github.com/mdempsky/gocode
go get github.com/k0kubun/pp
brew install ghq
ghq list
#Output result example)
# golang.org/x/tools
# golang.org/x/xerrors
# golang.org/x/sys
# golang.org/x/text
# golang.org/x/mod
# github.com/peterh/liner
# github.com/k0kubun/pp
# github.com/motemen/gore
# github.com/motemen/go-quickfix
# github.com/mdempsky/gocode
# github.com/mattn/go-isatty
# github.com/mattn/go-runewidth
# github.com/mattn/go-colorable
git config --global ghq.root $GOPATH/src
ghq seems to be hitting the git command behind the scenes.
Other details will be dealt with as needed.
Recommended Posts