accounts/server/Makefile
2025-08-07 23:13:44 +08:00

69 lines
1.9 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.

APP_NAME := xcontrol-server
MAIN_FILE := ../cmd/api/main.go
MODULE := xcontrol
PORT := 3001
OS := $(shell uname -s)
.PHONY: all build run clean init help dev test
all: build
init:
@echo ">>> 初始化 Go 依赖环境"
@if command -v go >/dev/null 2>&1; then \
echo "Go 已安装"; \
else \
echo "安装 Go"; \
if [ "$(OS)" = "Darwin" ]; then \
brew install go@1.24 && brew link --overwrite --force go@1.24; \
else \
sudo apt-get update && sudo apt-get install -y golang; \
fi; \
fi
@if curl -s --max-time 5 https://goproxy.cn >/dev/null; then \
echo "使用国内镜像: goproxy.cn"; \
go env -w GOPROXY=https://goproxy.cn,direct; \
else \
echo "国内镜像不可用,使用默认: proxy.golang.org"; \
go env -w GOPROXY=https://proxy.golang.org,direct; \
fi
@echo ">>> 执行 go mod tidy"
go mod tidy
@echo ">>> 可选安装 air (开发热重载)"
@echo "如需安装,请运行: go install github.com/air-verse/air@latest"
build:
@echo ">>> 编译 $(APP_NAME)"
go build -o $(APP_NAME) $(MAIN_FILE)
run:
@echo ">>> 运行 $(APP_NAME) on port $(PORT) (后台运行)"
@nohup env PORT=$(PORT) go run $(MAIN_FILE) > $(APP_NAME).log 2>&1 &
test:
@echo ">>> 运行单元测试"
go test ./...
dev:
@echo ">>> 开发模式运行 $(APP_NAME) (热重载) on port $(PORT)"
@if command -v air >/dev/null; then \
PORT=$(PORT) air -c .air.toml; \
else \
echo "未检测到 air直接运行 go run"; \
PORT=$(PORT) go run $(MAIN_FILE); \
fi
clean:
@echo ">>> 清理构建产物"
rm -f $(APP_NAME)
help:
@echo " XControl Server Makefile"
@echo ""
@echo "make build 编译 server 可执行文件"
@echo "make run 后台运行 server (默认端口: $(PORT))"
@echo "make test 运行单元测试"
@echo "make dev 开发模式运行 (自动检测 air如无则用 go run)"
@echo "make init 初始化依赖(自动选择国内/默认 Go 模块代理air 可选)"
@echo "make clean 清理构建产物"