您好,登錄后才能下訂單哦!
今天小編給大家分享的是golint的使用方法介紹,很多人都不太了解,今天小編為了讓大家更加了解golint的使用方法,所以給大家總結(jié)了以下內(nèi)容,一起往下看吧。一定會(huì)有所收獲的哦。
根據(jù)作者的說(shuō)法:
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代碼中不夠規(guī)范的地方。
一、編譯及生成可執(zhí)行程序
1、下載golang 的 lint,下載地址:https://github.com/golang/lint
2、解壓文件到$GOPATH/src/github.com/golang/lint
3、到目錄$GOPATH/src/github.com/golang/lint/golint中運(yùn)行g(shù)o build ./
4、在當(dāng)前目錄有g(shù)olint的可執(zhí)行程序
當(dāng)然,最簡(jiǎn)單的方式是:
go get github.com/golang/lint go install github.com/golang/lint
二、執(zhí)行方式:
golint 文件名或者目錄
檢查結(jié)果如下:
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對(duì)go代碼給出的建議。
golint 會(huì)檢查的內(nèi)容:
變量名規(guī)范
變量的聲明,像var str string = "test",會(huì)有警告,應(yīng)該var str = "test"
大小寫(xiě)問(wèn)題,大寫(xiě)導(dǎo)出包的要有注釋
x += 1 應(yīng)該 x++
以上就是golint的使用方法的簡(jiǎn)略介紹,當(dāng)然詳細(xì)使用上面的不同還得要大家自己使用過(guò)才領(lǐng)會(huì)。如果想了解更多,歡迎關(guān)注億速云行業(yè)資訊頻道哦!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。