测试
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构建系统集成,并提供足够的可定制性以适合您的工作流程。
请发表评论