您现在的位置是:群英 > 开发技术 > 编程语言
golint的使用方法是什么,可以用来做什么
Admin发表于 2022-06-28 17:08:021018 次浏览
这篇文章主要为大家详细介绍了golint的使用方法是什么,可以用来做什么,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望对大家学习或工作能有帮助。


 

根据作者的说法:

Golint is a linter for Go source code.

Golint differs from gofmt. Gofmt reformats Go source code, whereas

golint prints out style mistakes.

Golint differs from govet. Govet is concerned with correctness, whereas

golint is concerned with coding style. Golint is in use at Google, and it

seeks to match the accepted style of the open source Go project.

一句话就是Golint用于检查go代码中不够规范的地方。

一、编译及生成可执行程序

1、下载golang 的 lint,下载地址:https://github.com/golang/lint

2、解压文件到$GOPATH/src/github.com/golang/lint

3、到目录$GOPATH/src/github.com/golang/lint/golint中运行go build ./

4、在当前目录有golint的可执行程序

当然,最简单的方式是:

go get github.com/golang/lint
go install github.com/golang/lint

二、执行方式:

golint 文件名或者目录

检查结果如下:

import-dot.go:6:8: should not use dot imports
else.go:11:9: if block ends with a return statement, so drop this else and outdent its block
sort.go:11:1: exported method T.Len should have comment or be unexported
sort.go:20:1: exported method U.Other should have comment or be unexported

从上面输出可以看到,golint对go代码给出的建议。

golint 会检查的内容:

变量名规范

变量的声明,像var str string = "test",会有警告,应该var str = "test"

大小写问题,大写导出包的要有注释

x += 1 应该 x++



关于“golint的使用方法是什么,可以用来做什么”的内容就介绍到这,感谢各位的阅读,相信大家对golint的使用方法是什么,可以用来做什么已经有了进一步的了解。大家如果还想学习更多知识,欢迎关注群英网络,小编将为大家输出更多高质量的实用文章!

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。

相关信息推荐
2022-07-11 17:53:58 
摘要:实现步骤:1、自定义一个过滤函数,用于处理数组,返回值不等于3的数组元素,语法为“function 函数名($num){return($num!=3);}”;2、使用array_filter()函数调用自定义的过滤函数处理指定数组即可,“array_filter($arr,"函数名")”。
2022-07-25 17:49:12 
摘要:bootstrap设置字体的方法:首先正常引入bootstrap的css样式;然后在“main.css”中的第一句加上代码为“body,button, input, select, textarea,h1 ,h2...{...}”即可。
2022-06-28 17:08:04 
摘要:golang封装路由的方法:1、路由写在main函数中,数据库初始连接放在init()函数中。2、路由和db单独封装到一个函数中,以传参的形式将路由传给另一个函数。
云活动
推荐内容
热门关键词
热门信息
群英网络助力开启安全的云计算之旅
立即注册,领取新人大礼包
  • 联系我们
  • 24小时售后:4006784567
  • 24小时TEL :0668-2555666
  • 售前咨询TEL:400-678-4567

  • 官方微信

    官方微信
Copyright  ©  QY  Network  Company  Ltd. All  Rights  Reserved. 2003-2019  群英网络  版权所有   茂名市群英网络有限公司
增值电信经营许可证 : B1.B2-20140078   粤ICP备09006778号
免费拨打  400-678-4567
免费拨打  400-678-4567 免费拨打 400-678-4567 或 0668-2555555
微信公众号
返回顶部
返回顶部 返回顶部