go imports 配置

gofmt 保存的时候自动 格式化go代码

goimports 保存的时候自动导入处理包

gometalinter 保存的时候自动检查go语法

首先检查file Watchers有没有开启

goimports需要先goget 才可以使用

go get golang.org/x/tools/cmd/goimports

如果没有翻墙的话,获取不到。国内需要翻墙才可以从golang.org获取到。

192:go wuzhiyuan$ go get golang.org/x/tools/cmd/goimports
package golang.org/x/tools/cmd/goimports: unrecognized import path "golang.org/x/tools/cmd/goimports" (https fetch: Get https://golang.org/x/tools/cmd/goimports?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)

从GitHub上获取:
go get -v github.com/gpmgo/gopm

如果遇到下面的报错: could not read Username for 'https://github.com':

# cd .; git clone https://github.com/gpmgo/gopm /Users/wuzhiyuan/go/src/github.com/gpmgo/gopm
Cloning into '/Users/wuzhiyuan/go/src/github.com/gpmgo/gopm'...
fatal: could not read Username for 'https://github.com': terminal prompts disabled
package github.com/gpmgo/gopm: exit status 128

先检查你的库名是否拼对,再查看有没有将username和email加入到git,可以使用如下命令:

git config --global user.name "yourname"
git config --global user.email "youremail"

gopm 获取完成后需要获取goimports:
gopm get -g -v golang.org/x/tools/cmd/goimports

获取成功:

192:go wuzhiyuan$ gopm get -g -v golang.org/x/tools/cmd/goimports
[GOPM] 12-03 16:12:10 [ INFO] App Version: 0.8.8.0307 Beta
[GOPM] 12-03 16:12:10 [ INFO] Local repository path: /Users/wuzhiyuan/.gopm/repos
[GOPM] 12-03 16:12:10 [ INFO] Indicated GOPATH: /Users/wuzhiyuan/go
[GOPM] 12-03 16:12:10 [ INFO] Downloading package: golang.org/x/tools/cmd/goimports@branch:
[GOPM] 12-03 16:15:35 [DEBUG] Linking golang.org/x/tools...
[GOPM] 12-03 16:15:35 [ INFO] Got golang.org/x/tools/cmd/goimports@branch:
[GOPM] 12-03 16:15:35 [ INFO] Package copied to GOPATH: golang.org/x/tools
[GOPM] 12-03 16:15:35 [ INFO] 1 package(s) downloaded, 0 failed

查看goimports文件夹内容,已经全都拉取下来了

192:go wuzhiyuan$ ls src/golang.org/x/tools/cmd/goimports/
doc.go                  goimports.go            goimports_gc.go         goimports_not_gc.go

IDE里面也可以看到目录:


External Libraries

进入IDE偏好设置,添加goimports:


添加goimports

你可能感兴趣的:(go imports 配置)