在Go中轻松安全地从一种数据类型转换为另一种数据类型
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

41 lines
1.1 KiB

  1. GOVERSION := $(shell go version | cut -d ' ' -f 3 | cut -d '.' -f 2)
  2. .PHONY: check fmt lint test test-race vet test-cover-html help
  3. .DEFAULT_GOAL := help
  4. check: test-race fmt vet lint ## Run tests and linters
  5. test: ## Run tests
  6. go test ./...
  7. test-race: ## Run tests with race detector
  8. go test -race ./...
  9. fmt: ## Run gofmt linter
  10. ifeq "$(GOVERSION)" "12"
  11. @for d in `go list` ; do \
  12. if [ "`gofmt -l -s $$GOPATH/src/$$d | tee /dev/stderr`" ]; then \
  13. echo "^ improperly formatted go files" && echo && exit 1; \
  14. fi \
  15. done
  16. endif
  17. lint: ## Run golint linter
  18. @for d in `go list` ; do \
  19. if [ "`golint $$d | tee /dev/stderr`" ]; then \
  20. echo "^ golint errors!" && echo && exit 1; \
  21. fi \
  22. done
  23. vet: ## Run go vet linter
  24. @if [ "`go vet | tee /dev/stderr`" ]; then \
  25. echo "^ go vet errors!" && echo && exit 1; \
  26. fi
  27. test-cover-html: ## Generate test coverage report
  28. go test -coverprofile=coverage.out -covermode=count
  29. go tool cover -func=coverage.out
  30. help:
  31. @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'