Goland开发秘笈

Table of Contents

1. File Watchers 插件安装

1.1 File Watchers配置参数说明:

2. gofmt插件配置

3. goimports插件配置

4. golint配置到File Watchers

3.1 示例


   

 跟Vim, VSCode一样,GoLand也支持在保存代码时,自动调用 gofmt 和 goimports 来自动格式化代码。但是在网上搜到的都是之前版本的GoLand配置,在最新版的GoLand中,是通过File Watchers插件来实现此功能的。

1. File Watchers 插件安装

安装”File Watchers”的插件,并设置为启用状态

 

在Tools -> File Watchers中,添加如下设置:

 

1.1 File Watchers配置参数说明:

Name : golint #Tool名称 Description: golint #Tool描述 Program : $GOPATH\bin\golint.exe #选择golint可执行文件的位置 Atguments: $FilePath$ #魔法变量(执行当前go文件的路径) Working directory: $ProjectFileDir$ #魔法变量(当前项目的路径)

 

2. gofmt插件配置

 

3. goimports插件配置

 

4. golint配置到File Watchers

在Tools -> File Watchers -> custom中,添加如下设置:

3.1 示例

修改前文件

// ObtainPD Post Data
type ObtainPD struct {
	CouponTemplateID int64  `json:"coupon_template_id"`
	AppKey           string `json:"app_key"`
	UID              int64  `json:"uid"`
}

修改后文件

// Obtain PD Post Data
type ObtainPD struct {
	CouponTemplateID int64  `json:"coupon_template_id"`
	AppKey           string `json:"app_key"`
	UID              int64  `json:"uid"`
}

保存时文件时自动执行golint

$GOPATH/bin/golint PathTo/controllers/coupon/obtain.goPathTo/controllers/coupon/obtain.go:13:1: comment on exported type ObtainPD should be of the form "ObtainPD ..." (with optional leading article)

Process finished with exit code 0

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值