33

Goland辅助工具goimports和gomodules

 4 years ago
source link: https://studygolang.com/articles/27386
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

1、goimports工具

goimports工具是Go官方提供的一种工具,它能够为我们自动格式化 Go 语言代码并对所有引入的包进行管理,包括自动增删依赖的包引用、将依赖包按字母序排序并分类。

我们在使用Goland IDE的时候,建议使用goimports工具。它具备包依赖管理+gofmt的功能。

具体配置如下:

Jv22qeB.jpg!web

图1 选择Setting->Tools->File Watchers

uaauyeE.jpg!web

图2 添加goimports工具

2、gomodules工具

Go 1.11 之后官方支持的版本管理工具 mod,推荐使用 go mod 作为包管理工具。

如果使用goland,配置go Modules 相关,需要在Goland IDE中勾选 Vendoring mode。

有些依赖包如果没法下载,可以设定Proxy。

可以通过 export GOPROXY= https://goproxy. cn 指定。

一般我们使用的国内go代理有以下几种:

http://goproxy.cn :由七牛云运行,支持代理  http://sum.golang.org ,经过 CDN 加速,高可用,可应用进公司复杂的开发环境中,亦可用作上游代理;

http://mirrors.aliyun.com/goproxy :由阿里云运行,不支持 sumdb 代理,经过 CDN 加速,高可用,可应用进公司复杂的开发环境中,亦可用作上游代理;

http://goproxy.io :由个人运行,支持代理  http://sum.golang.org

大家可以根据喜好自由选择。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK