Goland 配置规范

星期二, 9月 12, 2023 | 1分钟阅读 | 更新于 星期二, 9月 12, 2023

@

在 Actions on Save 时选择 Reformat code 和 Optimize imports 可以自动格式化代码和引用包。

设置自动代码格式化,在保存文件(Ctr + S)时触发自动格式化。

 (https://developer.qcloudimg.com/http-save/yehe-900000/1d1a24ca25f9d87e74ca890ac4aa9cf6.png)

在 Actions on Save 时选择 Reformat code 和 Optimize imports 可以自动格式化代码和引用包。

还可以通过自定义文件(File Watchers)变动的动作,如执行 go fmt 格式化代码,在保存文件时生效。引入其它工具也是类似步骤。

(1)File Watcher 中添加 go fmt

 (https://developer.qcloudimg.com/http-save/yehe-900000/2743c29b719b9620c26ec9f8616459ea.png)

(2)勾选 go fmt 可执行文件路径,默认为 $GoExecPath$

 (https://developer.qcloudimg.com/http-save/yehe-900000/6067ace3a433a6a420b19dd2a7bf39ac.png)

(3)设置 go fmt 工具为 Global 范围。

 (https://developer.qcloudimg.com/http-save/yehe-900000/41beaa00165f0b2d33522967ebfc6ee9.png)

(1)设置换行为 Linux 或 macOS 风格,且单行列数不超过 120。

 (https://developer.qcloudimg.com/http-save/yehe-900000/ba00c06c7054e36dc0aca6e15b7c892b.png)

(2)在代码中取消使用 tab 格式,按 tab 缩进时用 4 个空格替代单个 tab 格式。

 (https://developer.qcloudimg.com/http-save/yehe-900000/08b09f111871a9c6e241441ecacb4ad3.png)

(3)设置自动分组引入包和去除重复包。

 (https://developer.qcloudimg.com/http-save/yehe-900000/b2c54b3fc3d2e81d16eb4f66bca61b39.png)

(4)在注释符和注释内容直接添加一个空格。

 (https://developer.qcloudimg.com/http-save/yehe-900000/1b7f1526f92a835cba7dc649a0a773c5.png)

(5)统一设置文件编码为 UTF-8 格式。

 (https://developer.qcloudimg.com/http-save/yehe-900000/d1013d9bf4206035323ee9206d33826b.png)

(1)在导入 Go moudles 项目时需要勾选这个 Enable Go modules integration,可以让 IDE 更快导入和分析代码。

 (https://developer.qcloudimg.com/http-save/yehe-900000/dedaffbeca9b8a733e42e546045925bb.png)

(2)在 IDE 拉取依赖包时出现访问工蜂报错 x509:certificate signed by unknown authority 错误,需要设置 Go 的环境变量,复制并修改以下的三个环境变量命令为 go env -w Key=Value 形式:

go env -w GOPROXY="https://yourUserName:yourAutoGeneratedToken@goproxy.com,direct" 
go env -w GOSUMDB="sum.com.xxx"
go env -w GOPRIVATE=""

写入到 GOENV(跨系统、立即生效,推荐!!!注意此时环境变量别再配置这三个变量,也别在 GoLand Setting 内配置这三个变量)。

comments powered by Disqus

© 2018 - 2025 DiyBeta's Blog

Powered by Hugo & Dream

Me

Cut out summary from your post content here.

The remaining content of your post.