## 主要功能 - ✅ 用户认证模块 (登录/注册/JWT) - ✅ 照片管理模块 (上传/查询/分页/搜索) - ✅ 分类管理模块 (创建/查询/分页) - ✅ 用户管理模块 (用户列表/分页查询) - ✅ 健康检查接口 ## 技术实现 - 基于 go-zero v1.8.0 标准架构 - Handler → Logic → Model 三层架构 - SQLite/PostgreSQL 数据库支持 - JWT 认证机制 - bcrypt 密码加密 - 统一响应格式 - 自定义模型方法 (分页/搜索) ## API 接口 - POST /api/v1/auth/login - 用户登录 - POST /api/v1/auth/register - 用户注册 - GET /api/v1/health - 健康检查 - GET /api/v1/photos - 照片列表 - POST /api/v1/photos - 上传照片 - GET /api/v1/categories - 分类列表 - POST /api/v1/categories - 创建分类 - GET /api/v1/users - 用户列表 ## 配置完成 - 开发环境配置 (SQLite) - 生产环境支持 (PostgreSQL) - JWT 认证配置 - 文件上传配置 - Makefile 构建脚本 服务已验证可正常构建和启动。
102 lines
2.5 KiB
Makefile
102 lines
2.5 KiB
Makefile
# Photography Backend Makefile
|
|
|
|
# 默认配置
|
|
BINARY_NAME=photography-api
|
|
BUILD_DIR=bin
|
|
CONFIG_FILE=etc/photographyapi-api.yaml
|
|
|
|
# 环境变量
|
|
export GO111MODULE=on
|
|
export GOPROXY=https://goproxy.cn,direct
|
|
|
|
# 构建
|
|
build:
|
|
@echo "Building $(BINARY_NAME)..."
|
|
@mkdir -p $(BUILD_DIR)
|
|
go build -o $(BUILD_DIR)/$(BINARY_NAME) cmd/api/main.go
|
|
|
|
# 运行
|
|
run:
|
|
@echo "Running $(BINARY_NAME)..."
|
|
@./$(BUILD_DIR)/$(BINARY_NAME) -f $(CONFIG_FILE)
|
|
|
|
# 开发模式(构建并运行)
|
|
dev: build run
|
|
|
|
# 快速启动(跳过构建)
|
|
quick:
|
|
@echo "Quick start $(BINARY_NAME)..."
|
|
@go run cmd/api/main.go -f $(CONFIG_FILE)
|
|
|
|
# 安装依赖
|
|
install:
|
|
@echo "Installing dependencies..."
|
|
@go mod tidy
|
|
|
|
# 代码生成
|
|
gen:
|
|
@echo "Generating code..."
|
|
@goctl api go -api api/desc/photography.api -dir ./ --style=goZero
|
|
|
|
# 生成模型
|
|
gen-model:
|
|
@echo "Generating models..."
|
|
@goctl model mysql ddl -src internal/model/sql/user.sql -dir internal/model/
|
|
@goctl model mysql ddl -src internal/model/sql/photo.sql -dir internal/model/
|
|
@goctl model mysql ddl -src internal/model/sql/category.sql -dir internal/model/
|
|
|
|
# 清理
|
|
clean:
|
|
@echo "Cleaning..."
|
|
@rm -rf $(BUILD_DIR)
|
|
@go clean
|
|
|
|
# 代码检查
|
|
lint:
|
|
@echo "Running linter..."
|
|
@golangci-lint run
|
|
|
|
# 格式化代码
|
|
fmt:
|
|
@echo "Formatting code..."
|
|
@go fmt ./...
|
|
|
|
# 运行测试
|
|
test:
|
|
@echo "Running tests..."
|
|
@go test -v ./...
|
|
|
|
# 创建必要目录
|
|
setup:
|
|
@echo "Setting up directories..."
|
|
@mkdir -p data uploads $(BUILD_DIR)
|
|
|
|
# 健康检查
|
|
status:
|
|
@echo "API Status:"
|
|
@curl -s http://localhost:8080/api/v1/health || echo "API is not running"
|
|
|
|
# 部署准备
|
|
deploy-prep: clean install lint test build
|
|
@echo "Deployment preparation complete."
|
|
|
|
# 显示帮助
|
|
help:
|
|
@echo "Available commands:"
|
|
@echo " build - Build the application"
|
|
@echo " run - Run the application"
|
|
@echo " dev - Build and run in development mode"
|
|
@echo " quick - Quick start without building"
|
|
@echo " install - Install dependencies"
|
|
@echo " gen - Generate API code"
|
|
@echo " gen-model - Generate model code"
|
|
@echo " clean - Clean build artifacts"
|
|
@echo " lint - Run code linter"
|
|
@echo " fmt - Format code"
|
|
@echo " test - Run tests"
|
|
@echo " setup - Create necessary directories"
|
|
@echo " status - Check API status"
|
|
@echo " deploy-prep - Prepare for deployment"
|
|
@echo " help - Show this help message"
|
|
|
|
.PHONY: build run dev quick install gen gen-model clean lint fmt test setup status deploy-prep help |