配置ATOM Go开发环境
安装script插件,可以直接在ATOM运行GO代码
错误如下
:/usr/local$ go get -u github.com/nsf/gocode
go install github.com/nsf/gocode: open /usr/local/go/bin/gocode: permission denied
在/usr/local/go/bin
目录下手动创建gocode目录就可以解决
:/usr/local$ ls -la /usr/local/go/bin/
总用量 27504
drwxr-xr-x 2 root root 4096 8月 9 03:21 .
drwxr-xr-x 11 root root 4096 8月 9 03:21 ..
-rwxr-xr-x 1 root root 9953979 8月 9 03:19 go
-rwxr-xr-x 1 root root 15156811 8月 9 03:21 godoc
-rwxr-xr-x 1 root root 3036195 8月 9 03:18 gofmt
:/usr/local$ sudo mkdir /usr/local/go/bin/gocode
:/usr/local$ go get -u github.com/nsf/gocode
go install github.com/derekparker/delve/cmd/dlv: open /usr/local/go/bin/dlv: permission denied
同样在/usr/local/go/bin
目录下手动创建dlv目录就可以解决
参考 这个
$GOPATH not set 问题解决方案
环境配置:
$ env | grep GO
GOBIN=/usr/local/go/bin
GOARCH=amd64
GOROOT=/usr/local/go
GOOS=darwin
GOPATH=/Users/ryan/go
执行安装
sudo go get github.com/nsf/gocode
提示:
cannot download, $GOPATH not set. For more details see: go help gopath
解决方案,在安装命令前手动指定GOPATH的环境变量:
sudo env GOPATH=XXXX(实际的GOPATH) go get github.com/nsf/gocode
为了方便程序跳转,安装atom-ctags插件时出现问题
At Cannot find module '/usr/lib/electron/resources/app.asar.unpacked/node_modules/symbols-view/node_modules/ctags/build/Release/ctags.node'
Error: Cannot find module '/usr/lib/electron/resources/app.asar.unpacked/node_modules/symbols-view/node_modules/ctags/build/Release/ctags.node'
at Module._resolveFilename (module.js:338:15)
at Function.Module._resolveFilename (/usr/lib/atom/src/module-cache.js:383:52)
at Function.Module._load (module.js:289:25)
at Module.require (module.js:366:17)
解决方案:
$ vim ~/.atom/packages/atom-ctags/node_modules/ctags/src/ctags.coffee
{Tags} = require(process.resourcesPath + '/../../atom/node_modules/symbols-view/node_modules/ctags/build/Release/ctags.node')
#{Tags} = require(process.resourcesPath + '/app.asar.unpacked/node_modules/symbols-view/node_modules/ctags/build/Release/ctags.node')
/usr/share/atom/resources/app.asar.unpacked/node_modules/symbols-view/node_modules/ctags/build/Release/ctags.node
vscode配置go开发环境
参考ATOM的方法
如果运行时提示如下错误
go: GOPATH entry is relative; must be absolute path: "".
Run 'go help gopath' for usage.
exit status 2
则修改vs项目下的launch.json文件
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {
"GOPATH": "/home/XXX/goproj:/home/XXX/project2",
"GOROOT": "/usr/local/go"
},
"args": []
}
]
}
注意不同目录用:
区分
sudo env GOPATH=/home/XXX/goproj go get -v golang.org/x/tools/cmd/guru
在实际开发中,发现vscode比atom更加方便,除了支持代码跳转外,vscode在插件配置好后,在ctrl+s后会自动错误检测并编译项目。