这篇文章主要讲解了“Go代码检查的工具如何使用”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Go代码检查的工具如何使用”吧!(1)安装golint(2)使用方式(3)golint校验规则不能使用下划线命名法,使用驼峰命名法外部可见程序结构体、变量、函数都需要注释通用名词要求大写 iD/Id -> ID Http -> HTTP Json -> JSON Url -> URL Ip -> IP Sql -> SQL包命名统一小写不使用驼峰和下划线注释第一个单词要求是注释程序主体的名称,注释可选不是必须的外部可见程序实体不建议再加包名前缀if语句包含return时,后续代码不能包含在else里面errors.New(fmt.Sprintf(…)) 建议写成 fmt.Errorf(…)receiver名称不能为this或selfreceiver名称不能为this或self错误变量命名需以 Err/err 开头a+=1应该改成a++,a-=1应该改成a–(4)检查的结果示例如下:middlewares.go:29:6: exported type xxxInstrumentingMiddleware should have comment or be unexported
middlewares.go:41:1: error should be the last type when returning multiple items
middlewares.go:41:1: exported method xxxInstrumentingMiddleware.Creativexxx should have comment or be unexported
middlewares.go:88:1: error should be the last type when returning multiple items
middlewares.go:88:1: exported method xxxInstrumentingMiddleware.CreativexxxRTB should have comment or be unexported
middlewares.go:135:1: error should be the last type when returning multiple items
middlewares.go:135:1: exported method xxxInstrumentingMiddleware.UpdateConf should have comment or be unexported
middlewares.go:141:1: error should be the last type when returning multiple items
middlewares.go:141:1: exported method xxxInstrumentingMiddleware.GetConf should have comment or be unexported
middlewares.go:147:1: exported function NewWrappedxxxInstrumentingMiddleware should have comment or be unexported
middlewares.go:218:6: exported type xxxInstrumentingMiddleware should have comment or be unexported
middlewares.go:225:1: exported method xxxInstrumentingMiddleware.PredictGRPC should have comment or be unexported
middlewares.go:250:1: exported function NewxxxInstrumentingMiddleware should have comment or be unexported
middlewares.go:281:6: exported type xxxxxxInstrumentingMiddleware should have comment or be unexported
middlewares.go:288:1: exported method xxxxxxInstrumentingMiddleware.PredictGRPC should have comment or be unexported
middlewares.go:288:116: method parameter appId should be appID
middlewares.go:306:1: exported function NewxxxxxxInstrumentingMiddleware should have comment or be unexported
xxx_callee.go:1:1: package comment should be of the form “Package xxxservice …”
xxx_callee.go:1:1: package comment should not have leading space
xxx_callee.go:1:1: package comment should be of the form “Package xxxservice …”
xxx_callee.go:1:1: package comment should not have leading space
xxx_callee.go:1:1: package comment should be of the form “Package xxxservice …”
xxx_callee.go:1:1: package comment should not have leading space
xxx_callee.go:38:96: method parameter appId should be appID
service.go:124:5: exported const xxxLevelLowerLimit should have comment (or a comment on this block) or be unexported
service.go:134:6: exported type xxxTdbankConfig should have comment or be unexported
service.go:138:6: exported type xxxConfig should have comment or be unexported
service.go:152:6: exported type xxxResponse should have comment or be unexported
service.go:162:6: exported type xxxMetaDataCache should have comment or be unexported
service.go:515:1: error should be the last type when returning multiple items
service.go:592:9: range var appId should be appID
service.go:604:16: range var appIdStr should be appIDStr
service.go:609:17: var appId should be appID
service.go:688:13: range var appId should be appID
service.go:801:13: range var appId should be appID
service.go:806:13: var behaviorGameIdList should be behaviorGameIDList(1)安装golangci-lint(2)使用方式(3)golangci-lint校验规则golangci-lint运行时会在当前目录查找配置文件golangci.yml.golangci.yaml.golangci.toml.golangci.json(4)检查的结果示例如下,-v参数可以看到更详细的检查结果# golangci-lint run -v service/service.go
INFO [config_reader] Config search paths: [./ /data/xxx/code/xxx/internal/xxx/service /data/xxx/code/xxx/internal/xxx /data/xxx/code/xxx/internal /data/xxx/code/xxx /data/xxx/code /data/xxx /data / /root]
INFO [lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]
INFO [loader] Go packages loading at mode 575 (compiled_files|exports_file|name|types_sizes|deps|files|imports) took 448.248885ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 7.130535ms
INFO [linters context/goanalysis] analyzers took 4.744573ms with top 10 stages: buildir: 629.354s, fact_deprecated: 514.772s, inspect: 435.291s, ctrlflow: 362.378s, typedness: 353.563s, printf: 345.2s, SA5012: 345.028s, fact_purity: 333.959s, nilness: 333.457s, isgenerated: 28.152s
INFO [runner/max_same_issues] 1/4 issues with text “undeclared name: `ModelInstrumentingMiddleware`” were hidden, use –max-same-issues
INFO [runner/max_same_issues] 1/4 issues with text “undeclared name: `NewModelInstrumentingMiddleware`” were hidden, use –max-same-issues
INFO [runner] Issues before processing: 2608, after processing: 9
INFO [runner] Processors filtering stat (out/in): skip_files: 2608/2608, max_from_linter: 9/9, path_shortener: 9/9, path_prefixer: 9/9, skip_dirs: 2608/2608, identifier_marker: 2608/2608, exclude: 2608/2608, nolint: 2608/2608, diff: 11/11, max_per_file_from_linter: 11/11, severity-rules: 9/9, sort_results: 9/9, filename_unadjuster: 2608/2608, path_prettifier: 2608/2608, autogenerated_exclude: 2608/2608, exclude-rules: 2608/2608, source_code: 9/9, cgo: 2608/2608, uniq_by_line: 11/2608, max_same_issues: 9/11
INFO [runner] processing took 103.631607ms with stages: exclude-rules: 61.093674ms, identifier_marker: 32.814984ms, nolint: 7.481643ms, path_prettifier: 1.299346ms, skip_dirs: 217.899s, uniq_by_line: 187.231s, source_code: 145.003s, filename_unadjuster: 132.84s, cgo: 117.621s, autogenerated_exclude: 93.646s, max_same_issues: 37.831s, path_shortener: 2.715s, max_from_linter: 2.375s, max_per_file_from_linter: 1.845s, exclude: 621ns, severity-rules: 511ns, sort_results: 490ns, skip_files: 471ns, diff: 470ns, path_prefixer: 391ns
INFO [runner] linters took 434.383892ms with stages: goanalysis_metalinter: 330.666778ms
service/service.go:72:29: undeclared name: `ModelInstrumentingMiddleware` (typecheck)
xxxService *免费云主机域名ModelInstrumentingMiddleware
^
service/service.go:73:29: undeclared name: `ModelInstrumentingMiddleware` (typecheck)
xxxCalibrationService *ModelInstrumentingMiddleware
^
service/service.go:74:29: undeclared name: `ModelInstrumentingMiddleware` (typecheck)
xxxCalibrationService *ModelInstrumentingMiddleware
^
service/service.go:76:29: undeclared name: `xxxModelInstrumentingMiddleware` (typecheck)
xxxService *xxxModelInstrumentingMiddleware
^
service/service.go:412:33: undeclared name: `NewModelInstrumentingMiddleware` (typecheck)
xxxService: NewModelInstrumentingMiddleware(NewxxxService(logger), “xxx_MODEL”),
^
service/service.go:413:33: undeclared name: `NewModelInstrumentingMiddleware` (typecheck)
xxxCalibrationService: NewModelInstrumentingMiddleware(NewxxxCalibrationService(logger), “xxx_CALIBRATION_MODEL”),
^
service/service.go:414:33: undeclared name: `NewModelInstrumentingMiddleware` (typecheck)
xxxService: NewModelInstrumentingMiddleware(NewxxxService(logger), “xxx_MODEL”),
^
service/service.go:416:33: undeclared name: `NewxxxModelInstrumentingMiddleware` (typecheck)
xxxService: NewxxxModelInstrumentingMiddleware(NewxxxService(logger), “xxx_MODEL”),
^
service/service.go:448:17: undeclared name: `NewWrappedxxxInstrumentingMiddleware` (typecheck)
wapedSvc := NewWrappedxxxInstrumentingMiddleware(svc)
^
INFO File cache stats: 1 entries of total size 183.6KiB
INFO Memory: 10 samples, avg is 70.1MB, max is 128.1MB
INFO Execution took 893.716ms1)安装codestyle(2)使用方式感谢各位的阅读,以上就是“Go代码检查的工具如何使用”的内容了,经过本文的学习后,相信大家对Go代码检查的工具如何使用这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是百云主机,小编将为大家推送更多相关知识点的文章,欢迎关注!
本文小编为大家详细介绍“怎么在Python中引用其他模块”,内容详细,步骤清晰,细节处理妥当,希望这篇“怎么在Python中引用其他模块”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。在Python中,除了可以自定义模块外,还可以引用…
免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。