首頁 > 後端開發 > Golang > 主體

golint的簡易使用方法

發布: 2020-04-15 17:56:25
轉載
4304 人瀏覽過

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。 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

更多golang開發知識請關注PHP中文網golang教程欄。

以上是golint的簡易使用方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
go
來源:oschina.net
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!