NAME=trace-backend VERSION=1.0.0 .PHONY: all clean build test test-coverage lint run # 默认任务 all: clean build # 清理二进制文件 clean: @echo "清理二进制文件..." @if exist $(NAME).exe del $(NAME).exe @if exist $(NAME) del $(NAME) @if exist coverage.out del coverage.out @if exist coverage.html del coverage.html # 编译 build: @echo "编译项目..." @go build -o $(NAME).exe main.go # 运行 run: @echo "启动服务器..." @go run main.go # 测试 test: @echo "运行测试..." @go test -v ./tests/... # 测试覆盖率 test-coverage: @echo "生成测试覆盖率报告..." @go test -v ./tests/... -coverprofile=coverage.out @go tool cover -html=coverage.out -o coverage.html @echo "测试覆盖率报告已生成: coverage.html" # 代码检查 lint: @echo "检查代码..." @golangci-lint run ./... # 格式化代码 fmt: @echo "格式化代码..." @gofmt -w . # 导入格式化 imports: @echo "格式化导入..." @goimports -w . # 代码质量检查(格式化 + 检查) quality: fmt imports lint # 安装依赖 deps: @echo "安装依赖..." @go mod tidy # 生成 Swagger 文档 swagger: @echo "生成 Swagger 文档..." @swag init -g main.go @echo "Swagger 文档已生成在 docs/ 目录" # 初始化数据库 init-db: @echo "初始化数据库..." @go run main.go # 编译为 Linux 版本 build-linux: @echo "编译 Linux 版本..." @set CGO_ENABLED=0 @set GOOS=linux @set GOARCH=amd64 @go build -o $(NAME) main.go # 编译为 macOS 版本 build-mac: @echo "编译 macOS 版本..." @set CGO_ENABLED=0 @set GOOS=darwin @set GOARCH=arm64 @go build -o $(NAME) main.go