安装:
Linux:
wget https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz
tar -C /usr/local -zxvf go1.10.3.linux-amd64.tar.gz
vim /etc/profile
// 在最后一行添加
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
// wq保存退出后source一下
source /etc/profile
Go
get download and install packages and dependencies
install compile and install packages and dependencies
文件放在$GOBIN下
build compile packages and dependencies
文件放在当前目录下
go build/get 编译生成的可执行文件位于:$GOBIN/bin下面。
GOPATH: 工作目录。 推荐:export GOPATH=~/golib
go get 下载的文件将放如$GOPATH的第一个工作区(第一个:之前的目录)/src 目录下。
GOROOT="/usr/local/Cellar/go/1.10.2/libexec" #建议设置值:否则可能出现package errors: unrecognized import path "errors" (import path does not begin with hostname)
vscode编译go:
setting\go configure: edit with json
"files.autoSave": "onFocusChange",
"editor.formatOnSave": true,
"go.gopath": "/Users/mark/code/go", // 当前工作空间${wordspaceRoot}加上系统 GOPATH 目录
"go.goroot": "/usr/local/bin/go", // go 的安装目录
"go.formatTool": "goimports", //使用 goimports 工具进行代码格式化,或者使用 goreturns 和 gofmt
"go.buildOnSave": true, //在保存代码时自动编译代码
"go.lintOnSave": true, //在保存代码时自动检查代码可以优化的地方,并给出建议
"go.vetOnSave": false, //在保存代码时自动检查潜在的错误
"go.coverOnSave": false, //在保存代码时执行测试,并显示测试覆盖率
"go.useCodeSnippetsOnFunctionSuggest": true, //使用代码片段作为提示
"go.gocodeAutoBuild": false //代码自动编译构建
目录结构:
golib
├── bin
├── pkg
│ ├── darwin_amd64
│ └── dep
└── src
├── github.com
└── hello