最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Go代碼檢查的推薦工具及使用詳解

 更新時間:2022年07月27日 11:35:49   作者:Luoyger  
這篇文章主要為大家介紹了Go代碼檢查的推薦工具及使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

1. Golint

(1)安裝golint

git clone https://github.com/golang/lint.git 
cd lint/golint
go install

(2)使用方式

# 檢查單個文件
golint service.go
# 檢查當(dāng)前目錄所有.go文件,不會遞歸查找
golint

(3)golint校驗規(guī)則

  • 不能使用下劃線命名法,使用駝峰命名法
  • 外部可見程序結(jié)構(gòu)體、變量、函數(shù)都需要注釋
  • 通用名詞要求大寫 iD/Id -> ID Http -> HTTP Json -> JSON Url -> URL Ip -> IP Sql -> SQL
  • 包命名統(tǒng)一小寫不使用駝峰和下劃線
  • 注釋第一個單詞要求是注釋程序主體的名稱,注釋可選不是必須的
  • 外部可見程序?qū)嶓w不建議再加包名前綴
  • if語句包含return時,后續(xù)代碼不能包含在else里面
  • errors.New(fmt.Sprintf(…)) 建議寫成 fmt.Errorf(…)
  • receiver名稱不能為this或self
  • receiver名稱不能為this或self
  • 錯誤變量命名需以 Err/err 開頭
  • a+=1應(yīng)該改成a++,a-=1應(yīng)該改成a--

(4)檢查的結(jié)果示例如下:

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

IDE集成工具參考:http://m.fzitv.net/article/229273.htm

2. Golangci-lint

(1)安裝golangci-lint

curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.41.1
golangci-lint --version

(2)使用方式

# 檢查單個文件
golangci-lint run service.go
# 指定目錄
golangci-lint run internal/
# 檢查當(dāng)前目錄所有.go文件,會遞歸查找當(dāng)前目錄及子目錄
golangci-lint run

(3)golangci-lint校驗規(guī)則

golangci-lint運行時會在當(dāng)前目錄查找配置文件

  • golangci.yml
  • .golangci.yaml
  • .golangci.toml
  • .golangci.json

具體配置參考:

https://golangci-lint.run/usage/configuration/

(4)檢查的結(jié)果示例如下,-v參數(shù)可以看到更詳細的檢查結(jié)果

# 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.354µs, fact_deprecated: 514.772µs, inspect: 435.291µs, ctrlflow: 362.378µs, typedness: 353.563µs, printf: 345.2µs, SA5012: 345.028µs, fact_purity: 333.959µs, nilness: 333.457µs, isgenerated: 28.152µs
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.899µs, uniq_by_line: 187.231µs, source_code: 145.003µs, filename_unadjuster: 132.84µs, cgo: 117.621µs, autogenerated_exclude: 93.646µs, max_same_issues: 37.831µs, path_shortener: 2.715µs, max_from_linter: 2.375µs, max_per_file_from_linter: 1.845µs, 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.716ms

3. Go-reporter

github地址:https://github.com/qax-os/goreporter

1)安裝codestyle

# golang版本需要 >=1.6
yum -y install graphviz
go get -u github.com/360EntSecGroup-Skylar/goreporter

(2)使用方式

# 展示指令可用參數(shù)
goreporter -p [projectRelativePath] -r [reportPath] -e [exceptPackagesName] -f [json/html/text]  {-t templatePathIfHtml}
-version Version of GoReporter.
-p Must be a valid Golang project path.
-r Save the path to the report.
-e Exceptional packages (multiple separated by commas, for example: "linters/aligncheck,linters/cyclo" ).
-f report format json, html OR text.
-t Template path,if not specified, the default template will be used.
By default, the default template is used to generate reports in html format.

以上就是Go代碼檢查的推薦工具及使用詳解的詳細內(nèi)容,更多關(guān)于Go代碼檢查工具的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Go類型斷言提取測試接口值動態(tài)類型及靜態(tài)轉(zhuǎn)換確保類型接口編譯安全

    Go類型斷言提取測試接口值動態(tài)類型及靜態(tài)轉(zhuǎn)換確保類型接口編譯安全

    這篇文章主要為大家介紹了Go類型斷言提取測試接口值動態(tài)類型及靜態(tài)轉(zhuǎn)換確保類型實現(xiàn)特定接口的編譯時安全性詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-10-10
  • 深入了解Golang中的反射機制

    深入了解Golang中的反射機制

    反射是指在程序運行時動態(tài)地檢查和修改對象的能力,在Go語言中,通過反射可以在運行時檢查變量的類型、獲取結(jié)構(gòu)體字段和方法的信息,以及動態(tài)調(diào)用方法等操作,本文將帶你深入了解Golang中的反射機制,感興趣的同學(xué)可以跟著小編一起來學(xué)習(xí)
    2023-05-05
  • 關(guān)于golang高并發(fā)的實現(xiàn)與注意事項說明

    關(guān)于golang高并發(fā)的實現(xiàn)與注意事項說明

    這篇文章主要介紹了關(guān)于golang高并發(fā)的實現(xiàn)與注意事項說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-05-05
  • Golang語言的多種變量聲明方式與使用場景詳解

    Golang語言的多種變量聲明方式與使用場景詳解

    Golang當(dāng)中的變量類型和C/C++比較接近,一般用的比較多的也就是int,float和字符串,下面這篇文章主要給大家介紹了關(guān)于Golang語言的多種變量聲明方式與使用場景的相關(guān)資料,需要的朋友可以參考下
    2022-02-02
  • golang 解析word文檔操作

    golang 解析word文檔操作

    這篇文章主要介紹了golang 解析word文檔操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12
  • GO語言中Chan實現(xiàn)原理的示例詳解

    GO語言中Chan實現(xiàn)原理的示例詳解

    這篇文章主要為大家詳細介紹了Go語言中Chan實現(xiàn)原理的相關(guān)資料,文中的示例代碼講解詳細,對我們學(xué)習(xí)Go語言有一定的幫助,需要的可以參考一下
    2023-02-02
  • Golang 中 omitempty的作用

    Golang 中 omitempty的作用

    這篇文章主要介紹了Golang 中 omitempty的作用,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考一下,需要的小伙伴可以參考一下
    2022-07-07
  • Go語言中關(guān)于set的實現(xiàn)思考分析

    Go語言中關(guān)于set的實現(xiàn)思考分析

    Go?開發(fā)過程中有時我們需要集合(set)這種容器,但?Go?本身未內(nèi)置這種數(shù)據(jù)容器,故常常我們需要自己實現(xiàn),下面我們就來看看具體有哪些實現(xiàn)方法吧
    2024-01-01
  • golang根據(jù)URL獲取文件名的示例代碼

    golang根據(jù)URL獲取文件名的示例代碼

    這篇文章主要為大家詳細介紹了golang根據(jù)URL獲取文件名,文中的示例代碼講解詳細,對大家的學(xué)習(xí)或工作有一定的幫助,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-01-01
  • golang執(zhí)行命令獲取執(zhí)行結(jié)果狀態(tài)(推薦)

    golang執(zhí)行命令獲取執(zhí)行結(jié)果狀態(tài)(推薦)

    這篇文章主要介紹了golang執(zhí)行命令獲取執(zhí)行結(jié)果狀態(tài)的相關(guān)知識,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧
    2019-11-11

最新評論

兴安县| 台东县| 巨野县| 合山市| 和硕县| 林芝县| 呼和浩特市| 昌平区| 额济纳旗| 栾城县| 北流市| 金乡县| 钟祥市| 荃湾区| 山东省| 顺平县| 佛山市| 若羌县| 东台市| 九寨沟县| 台安县| 邵东县| 仁寿县| 民丰县| 三都| 运城市| 商城县| 周口市| 丹巴县| 崇州市| 临桂县| 平乐县| 昭平县| 烟台市| 柘荣县| 武宁县| 青州市| 山西省| 栾城县| 固原市| 井研县|