測試
github.com/onsi/ginkgo
github.com/onsi/gomega
go get -u github.com/onsi/ginkgo/ginkgo
github.com/smartystreets/goconvey/convey
https://github.com/stretchr/testify
性能負載測試和工具
https://github.com/tsenart/vegeta
https://github.com/rs/jplot
https://github.com/rs/jaggr
https://github.com/wg/wrk
rpc框架
rpcx
go-kit
https://github.com/go-kit/kit
http://gokit.io/
go 代碼檢測和測試
- gofmt
- Gofmt formats Go programs. We run gofmt -s on your code
- go_vet
- go vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string.
- gocyclo
- https://github.com/fzipp/gocyclo
- Gocyclo calculates cyclomatic complexities of functions in Go source code. The cyclomatic complexity of a function is calculated according to the following rules: 1 is the base complexity of a function +1 for each 'if', 'for', 'case', '&&' or '||' Go Report Card warns on functions with cyclomatic complexity > 15.
- golint
- Golint is a linter for Go source code
- license
- Checks whether your project has a LICENSE file.
- ineffassign
- IneffAssign detects ineffectual assignments in Go code.
- misspell
- Misspell Finds commonly misspelled English words
- https://github.com/client9/misspell
golangci
#代碼質量審查
run:
concurrency: 4
deadline: 2m
tests: false
skip-dirs:
- vendor
- test
skip-files:
output:
format: code-climate
print-issued-lines: true
print-linter-name: true
linters-settings:
errcheck:
check-type-assertions: false
golint:
min-confidence: 0.8
gofmt:
simplify: true
gocyclo:
min-complexity: 10
maligned:
suggest-new: true
dupl:
threshold: 100
linters:
enable-all: true
disable:
- lll
issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
exclude:
makefile
GOPATH:=$(shell go env GOPATH)
GoVersion=$(shell go version)
BuildTime=$(shell date +%F-%Z/%T)
CommitID=$(shell git rev-parse HEAD)
LDFLAGS=-ldflags "-X 'version.GoVersion=${GoVersion}' \
-X version.BuildTime=${BuildTime} \
-X version.CommitID=${CommitID}"
@go build ${LDFLAGS} -v -o user-api cmd/main.go
gocyclo
gocyclo 用來檢查函數的復雜度。
github.com/fzipp/gocyclo
gocyclo -over 12 $(ls -d */ | grep -v vendor)
interfacer
interfacer 是一個有趣的工具,依照作者所說:
這個工具提供接口類型的建議,換句話說,它會對可以本沒有必要定義成具體的類型的代碼提出警告
github.com/mvdan/interfacer/cmd/interfacer
deadcode
deadcode會告訴你哪些代碼片段根本沒用。
github.com/tsenart/deadcode
gotype
gotype會對go文件和包進行語義(semantic)和句法(syntactic)的分析,這是google提供的一個工具。
golang.org/x/tools/cmd/gotype
misspell
misspell用來拼寫檢查,對國內英語不太熟練的同學很有幫助。
github.com/client9/misspell
staticcheck
staticcheck是一個超牛的工具,提供了巨多的靜態檢查,就像 C#生態圈的 ReSharper 一樣。
honnef.co/go/staticcheck/cmd/staticcheck
gosimple
gosimple 提供信息,幫助你了解哪些代碼可以簡化。
honnef.co/go/simple/cmd/gosimple
譯者按: 事實上這個工具和上面的staticcheck工具已經合並為同一個項目了:go-tools,這個項目提供了非常好的工具, 還包括 structlayout-optimize、unused、rdeps、keyify等,值的你去探索。
goconst
goconst 會查找重復的字符串,這些字符串可以抽取成常量。
github.com/jgautheron/goconst/cmd/goconst
使用工具檢查你的代碼
https://colobu.com/2017/02/07/write-idiomatic-golang-codes/#使用工具檢查你的代碼
實效Go編程
https://go-zh.org/doc/effective_go.html
Staticcheck-先進的Go linter
https://github.com/dominikh/go-tools
honnef.co/go/tools/... 是用於處理Go代碼的工具和庫的集合,其中包括短絨和靜態分析,其中最突出的是staticcheck。
https://staticcheck.io/docs/
Staticcheck是用於Go編程語言的靜態分析工具集。 它帶有大量檢查,與各種Go構建系統集成,並提供足夠的可定制性以適合您的工作流程。