golang 程序检查工具及手法

代码检查工具

github地址及说明 https://github.com/golangci/golangci-lint

下载

linux/mac : go get -u github.com/golangci/golangci-lint/cmd/golangci-lint

mac:brew install golangci/tap/golangci-lint
    brew upgrade golangci/tap/golangci-lint
其他方法安装:
    # binary will be $(go env GOPATH)/bin/golangci-lint
    curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin vX.Y.Z
    
    # or install it into ./bin/
    curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s vX.Y.Z
    
    # In alpine linux (as it does not come with curl by default)
    wget -O - -q https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s vX.Y.Z
    
    # binary will be $(go env GOPATH)/bin/golangci-lint
    curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin vX.Y.Z
    
    # or install it into ./bin/
    curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s vX.Y.Z
    
    # In alpine linux (as it does not come with curl by default)
    wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s vX.Y.Z
##### 检查是否安装成功
    golangci-lint version

# 有可能遇到的安装问题

一、src下面的bin路径

二、可能需要再安装目录用一次啊go install

三、环境变量需要加进去 例如在 /etc/profile 加上 export PATH = $PATH:$GOPATH/bin

使用

检查代码规范错误:golangci-lint run <文件路径>

检查代码行数超限等:golangci-lint --disable-all -E=gocyclo run

 

检查内存占用

可以使用 golang 自身 
go tool pprof 

检查程序冲突

可以使用 golang 自身
go tool vet <>

检查channel占用

可以使用 golang 自身
go run/test -race <编译的包/.go文件>

后续有新的会继续补充 

你可能感兴趣的:(golang,web)