Golang安装与命令

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 := make(chan int, 2)

发送数据

resultChan <- <number>

提取数据

sum1 := <-resultChan

 

posted @ 2019-04-24 01:41  森淼clover  阅读(1286)  评论(0编辑  收藏  举报