# golang1.17.1 or latest # 1. make help # 2. make build # ... .PHONY: all build test fmt vet clean help RED=\033[0;31m GREEN=\033[0;32m BLUE=\033[0;34m NC=\033[0m build: @go mod tidy -v @go build -v ./... @printf "${GREEN}Build successfully!${NC}\n" .PHONY: test fmt_proto fmt_shell check checkgofmt help: Makefile @echo "Choose a command run:" @sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' ## make test: Run go unittest test: go generate ./... @$(GO) test ${TEST_PKGS} -count=1 mod: sed "s?)?$(MODS)\n)?" go.mod ## make linter: Run golanci-lint linter: golangci-lint run golangci-lint run -E goimports -E bodyclose --skip-dirs-use-default fmt_proto: ## go fmt protobuf file @find . -name '*.proto' -not -path "./vendor/*" | xargs clang-format -i fmt_shell: ## check shell file @find . -name '*.sh' -not -path "./vendor/*" | xargs shfmt -w -s -i 4 -ci -bn fmt_go: fmt_shell ## go fmt @go fmt ./... @find . -name '*.go' -not -path "./vendor/*" | xargs goimports -l -w goimports:fmt @CGO_ENABLED=1 goimports-reviser -dir-path ./ -project-name gitlab.33.cn/link33/chain33-sdk-go -ignore-dir mock -rm-unused -set-alias -format fmt: fmt_proto fmt_shell ## go fmt @go fmt ./... @find . -name '*.go' -not -path "./vendor/*" | xargs goimports -l -w @gofumpt -l -w . clean: @go clean build-dep: @go install golang.org/x/tools/cmd/goimports@latest @go install github.com/suyanlong/aligner@latest @go install mvdan.cc/gofumpt@latest @go install mvdan.cc/sh/v3/cmd/shfmt@latest @go install mvdan.cc/sh/v3/cmd/gosh@latest @go install mvdan.cc/unparam@latest @go install github.com/incu6us/goimports-reviser@master @go install github.com/psampaz/go-mod-outdated@v0.8.0 # @apt install clang-format or brew isntall clang-format # @apt install shellcheck or brew install shellcheck aligner: @aligner -r -c "//" -e ".go" comment aligner-check: @aligner -r -c "//" -e ".go" check checkgofmt: ## get all go files and run go fmt on them @files=$$(find . -name '*.go' -not -path "./vendor/*" | xargs gofmt -l -s); if [ -n "$$files" ]; then \ echo "Error: 'make fmt' needs to be run on:"; \ find . -name '*.go' -not -path "./vendor/*" | xargs gofmt -l -s ;\ exit 1; \ fi; @files=$$(find . -name '*.go' -not -path "./vendor/*" | xargs goimports -l -w); if [ -n "$$files" ]; then \ echo "Error: 'make fmt' needs to be run on:"; \ find . -name '*.go' -not -path "./vendor/*" | xargs goimports -l -w ;\ exit 1; \ fi; check: aligner-check checkgofmt modmated: @go list -u -m -json all | go-mod-outdated