1. 安裝
Windows - https://golang.org/dl/ 下載msi安裝包,點擊安裝即可。安裝后cmd運行go version彈出版本號即安裝成功。
linux -
sudo yum install golang
mkdir ~/workspace echo 'export GOPATH="$HOME/workspace"' >> ~/.bashrc source ~/.bashrc
Mac - https://golang.org/dl/ 下載對應版本,解壓到對應文件夾,配置Go Path
sudo tar -C /usr/local -xzf /home/nikhita/Downloads/go1.8.1.linux-amd64.tar.gz
echo $PATH | grep "/usr/local/go/bin"
FAQ :
1) compile: version "go1.12.5" does not match go tool version "go1.12.6"
go env里GOROOT指向了1.12.6,對應usr/local里版本是1.12.5。原因是homebrew update過一次,使得版本升級了一次,brew install go@版本號重新安裝時失敗,brew更新后沒有該版本go
GOROOT="/usr/local/Cellar/go/1.12.6/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.6/libexec/pkg/tool/darwin_amd64"
解決方式:
a)刪除/local下go tools
b) 按上述安裝過程下載對應版本后修復
2. 命令行
生成exe文件 - go build
運行 - go run [文件名]
查詢 - godoc 包名 方法名
3. IDE
Visual Studio Code - Go 插件。File Perference Setting里搜Go選中自動填充包
安裝和卸載教程 - https://golang.org/doc/install?download=go1.12.4.windows-amd64.msi
4. golang.org/x被qiang掉了怎么辦?
手動下載包到src/golang.org/x/下
git clone --depth=1 https://github.com/golang/xxx.git
-------------------command-----------------------
mkdir -p $GOPATH/src/golang.org/x/
cd !$
git clone https://github.com/golang/net.git
git clone https://github.com/golang/sys.git
git clone https://github.com/golang/tools.git
5. 各種
消息隊列 - 聲明
resultChan chan int
發送數據
resultChan <- <number>
提取數據
sum1 := <-resultChan