Files
web_template/Makefile
2026-07-10 10:05:51 +00:00

85 lines
2.0 KiB
Makefile
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ============================================
# Makefile — gotest 标准化构建命令
# 用法:make <target>
# ============================================
APP_NAME := gotest
BUILD_DIR := build
GO_LDFLAGS := -s -w
.DEFAULT_GOAL := help
## help: 显示所有可用命令
help:
@echo ""
@echo "$(APP_NAME) — 可用命令"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-18s\033[0m %s\n", $$1, $$2}'
@echo ""
## build: 编译二进制到 build/ 目录
build:
@echo "[BUILD] 编译 $(APP_NAME)..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 go build -ldflags="$(GO_LDFLAGS)" -o $(BUILD_DIR)/$(APP_NAME) .
@echo "[BUILD] 完成: $(BUILD_DIR)/$(APP_NAME)"
## run: 直接运行(go run)
run:
go run .
## build-prod: 生产级编译(prod 模式)
build-prod:
@echo "[BUILD] 生产级编译..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 APP_ENV=prod go build -ldflags="$(GO_LDFLAGS)" -o $(BUILD_DIR)/$(APP_NAME) .
@echo "[BUILD] 完成: $(BUILD_DIR)/$(APP_NAME)"
## test: 运行测试
test:
go test -v ./...
## fmt: 格式化代码
fmt:
go fmt ./...
## vet: 静态检查
vet:
go vet ./...
## lint: 完整代码检查 (fmt + vet)
lint: fmt vet
@echo "[LINT] 代码检查完成"
## docker-build: 构建 Docker 镜像
docker-build:
@echo "[DOCKER] 构建镜像..."
docker build -t $(APP_NAME):latest .
@echo "[DOCKER] 完成: $(APP_NAME):latest"
## docker-up: Docker Compose 启动全部服务
docker-up:
docker-compose up -d
@echo "[DOCKER] 服务已启动: http://localhost:8080"
## docker-down: Docker Compose 停止全部服务
docker-down:
docker-compose down
## clean: 清理构建产物
clean:
@echo "[CLEAN] 清理..."
rm -rf $(BUILD_DIR) data/app.db
@echo "[CLEAN] 完成"
## tidy: 整理 Go 模块依赖
tidy:
go mod tidy
## all: 完整流程 (lint → build → test)
all: lint build test
@echo "[ALL] 完整构建流程执行完毕"
.PHONY: help build run build-prod test fmt vet lint docker-build docker-up docker-down clean tidy all