golint 安装与使用

转行卖煎饼
• 阅读 2536

golint 可以对 go 源码进行静态编码检查,保证团队代码风格统一及编码规范。

golint 安装

传统又稳妥的安装方式

git clone https://github.com/golang/lint.git
cd lint/golint
go install
# 可以看到 golint 可执行文件
ll $GOBIN

可以看到 $GOBIN 下已经有 golint

golint 配置

goland 为例

external tools 配置
golint 安装与使用

快捷键配置
golint 安装与使用

golint 使用

  1. console下: golint file
  2. console下: golint directory
  3. pressKey: 选择文件直接按配置的快捷键

golint 规范

  1. don't use ALL_CAPS in Go names; use CamelCase
    不能使用下划线命名法,使用驼峰命名法
  1. exported function Xxx should have comment or be unexported
    外部可见程序结构体、变量、函数都需要注释
  1. var statJsonByte should be statJSONByte
    var taskId should be taskID
    通用名词要求大写
    iD/Id -> ID
    Http -> HTTP
    Json -> JSON
    Url -> URL
    Ip -> IP
    Sql -> SQL
  1. don't use an underscore in package name
    don't use MixedCaps in package name; xxXxx should be xxxxx
    包命名统一小写不使用驼峰和下划线
  1. comment on exported type Repo should be of the form "Repo ..." (with optional leading article)
    注释第一个单词要求是注释程序主体的名称,注释可选不是必须的
  1. type name will be used as user.UserModel by other packages, and that stutters; consider calling this Model
    外部可见程序实体不建议再加包名前缀
  1. if block ends with a return statement, so drop this else and outdent its block
    if语句包含return时,后续代码不能包含在else里面
  1. should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...) errors.New(fmt.Sprintf(…)) 建议写成 fmt.Errorf(…)
  1. receiver name should be a reflection of its identity; don't use generic names such as "this" or "self"
    receiver名称不能为this或self
  1. error var SampleError should have name of the form ErrSample
    错误变量命名需以 Err/err 开头
  1. should replace num += 1 with num++
    should replace num -= 1 with num--
    a+=1应该改成a++,a-=1应该改成a–
点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Wesley13 Wesley13
3年前
VBox 启动虚拟机失败
在Vbox(5.0.8版本)启动Ubuntu的虚拟机时,遇到错误信息:NtCreateFile(\\Device\\VBoxDrvStub)failed:0xc000000034STATUS\_OBJECT\_NAME\_NOT\_FOUND(0retries) (rc101)Makesurethekern
Wesley13 Wesley13
3年前
FLV文件格式
1.        FLV文件对齐方式FLV文件以大端对齐方式存放多字节整型。如存放数字无符号16位的数字300(0x012C),那么在FLV文件中存放的顺序是:|0x01|0x2C|。如果是无符号32位数字300(0x0000012C),那么在FLV文件中的存放顺序是:|0x00|0x00|0x00|0x01|0x2C。2.  
Stella981 Stella981
3年前
SpringBoot整合Redis乱码原因及解决方案
问题描述:springboot使用springdataredis存储数据时乱码rediskey/value出现\\xAC\\xED\\x00\\x05t\\x00\\x05问题分析:查看RedisTemplate类!(https://oscimg.oschina.net/oscnet/0a85565fa
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
PHP创建多级树型结构
<!lang:php<?php$areaarray(array('id'1,'pid'0,'name''中国'),array('id'5,'pid'0,'name''美国'),array('id'2,'pid'1,'name''吉林'),array('id'4,'pid'2,'n
Easter79 Easter79
3年前
SpringBoot整合Redis乱码原因及解决方案
问题描述:springboot使用springdataredis存储数据时乱码rediskey/value出现\\xAC\\xED\\x00\\x05t\\x00\\x05问题分析:查看RedisTemplate类!(https://oscimg.oschina.net/oscnet/0a85565fa
Wesley13 Wesley13
3年前
Java日期时间API系列36
  十二时辰,古代劳动人民把一昼夜划分成十二个时段,每一个时段叫一个时辰。二十四小时和十二时辰对照表:时辰时间24时制子时深夜11:00凌晨01:0023:0001:00丑时上午01:00上午03:0001:0003:00寅时上午03:00上午0
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
美凌格栋栋酱 美凌格栋栋酱
4个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(