Golang静态检查

golangci-lint安装及运行

go get -u github.com/golangci/golangci-lint

pushd ${GOPATH}/pkg/mod/github.com/golangci/golangci-lint@v1.41.1/cmd/golangci-lint
go build
cp golangci-lint /usr/bin
popd

#运行
golangci-lint run

code_check.sh

#!/usr/bin/env bash

function Fail() {
  echo "Abort with FAILs."
  exit 1
}

echo -e "Process go vet...\c"
go vet  $(go list ./... | grep -v /vendor/) || Fail
echo "PASS"

echo -e "Process ci-lint...\c"
which golangci-lint 1>/dev/null || (echo "Installing golangci-lint" && go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.32.2)
golangci-lint run --timeout 10m || Fail
echo "PASS"

echo -e "Process go test...\c"
go test $(go list ./... | grep -v /vendor/) -timeout=10s || Fail
echo "PASS"

echo "All check passed."

发表评论

邮箱地址不会被公开。 必填项已用*标注