-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
46 lines (37 loc) · 1.31 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
.PHONY: lint install-lint goimports install-goimports format clean
# 版本定义
GOLANGCI_LINT_VERSION ?= v1.61.0
GOIMPORTS_VERSION ?= v0.25.0
# Go 相关环境变量
GOBIN ?= $(shell go env GOPATH)/bin
# 检查是否安装了 golangci-lint
GOLANGCI_LINT ?= $(shell which golangci-lint || echo "$(GOBIN)/golangci-lint")
# 安装 golangci-lint(如果未安装)
install-lint:
@if ! command -v golangci-lint >/dev/null 2>&1; then \
echo "Installing golangci-lint $(GOLANGCI_LINT_VERSION)..."; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) $(GOLANGCI_LINT_VERSION); \
else \
echo "golangci-lint already installed"; \
fi
# 运行 lint 检查
lint: install-lint
@echo "Running golangci-lint..."
@$(GOLANGCI_LINT) run ./...
# goimports 执行路径
GOIMPORTS ?= $(shell which goimports || echo "$(GOBIN)/goimports")
# 安装 goimports(如果未安装)
install-goimports:
@if ! command -v goimports >/dev/null 2>&1; then \
echo "Installing goimports $(GOIMPORTS_VERSION)..."; \
go install golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION); \
else \
echo "goimports already installed"; \
fi
# 运行 goimports 格式化代码
format: install-goimports
@echo "Running goimports..."
@$(GOIMPORTS) -w .
# 清理临时文件
clean:
@rm -rf ./tmp