eafonyang b2aed2a6b5 feat(share): 新增 shareList 接口 + 分享码模块全链路优化
- 新增 GET /audio/shareList?mac=xx 查询未过期分享码(纯 Redis,ZSET 索引)
- share:mac:{mac} 从 SET 改为 ZSET(score=expire_at),支持 ZREMRANGEBYSCORE 精确过期清理
- 空 ZSET 自动 DEL,避免 key 累积
- share:import:pending 增加 12h 兜底 TTL,防止 DB 不可用时内存泄漏
- 导入日志 field 改为 mac:code(去掉 nanotime),同 MAC+code 多次导入幂等去重
- MarkPersisted 保存/恢复 PTTL,防御性编程
- shareCreate 改为 POST + JSON body
- 全量 handler 补充 Swagger 注释,集成 swag 文档生成
- Makefile 使用 $(go env GOPATH)/bin/swag 解决 PATH 问题
2026-06-12 17:07:59 +08:00
2026-06-12 15:50:01 +08:00
2026-06-12 15:50:01 +08:00
2026-06-05 20:15:30 +08:00
2026-06-05 14:03:34 +08:00
2026-06-12 15:50:01 +08:00
2026-06-04 19:39:08 +08:00
2026-06-12 15:50:01 +08:00
2026-06-12 15:50:01 +08:00

app-api

基于 Gin 的 Go HTTP API 脚手架。

项目结构

app-api/
├── cmd/server/          # 程序入口
├── internal/
│   ├── config/          # 配置加载
│   ├── handler/         # HTTP 处理器
│   ├── middleware/      # 中间件(日志、CORS、Request ID
│   ├── response/        # 统一 JSON 响应
│   └── router/          # 路由注册
└── pkg/logger/          # 可复用日志封装

快速开始

环境要求

  • Go 1.22+

安装依赖

go mod tidy

配置(可选)

复制环境变量示例:

cp .env.example .env
变量 默认值 说明
APP_ENV development 运行环境
APP_HOST 0.0.0.0 监听地址
APP_PORT 8080 监听端口
GIN_MODE debug Gin 运行模式

数据库

根据 APP_ENV 自动选择 MySQL 配置;也可通过 DATABASE_* 环境变量完全覆盖。

环境 APP_ENV 默认连接
开发 development 192.168.9.127:3306/audio(可通过 DATABASE_HOST 覆盖),用户 root,密码 root123
正式 production AWS RDS database-1.chmuueamo72p.eu-central-1.rds.amazonaws.com:3306/audio

正式环境密码必须通过环境变量 DATABASE_PASSWORD 提供(不要写入代码仓库)。可参考 .env.production.example

开发环境通过 .env 管理 MySQL / Redis 地址(host 变更时只需改 .env):

DATABASE_HOST=192.168.9.127
DATABASE_PORT=3306
DATABASE_NAME=audio
DATABASE_USER=root
DATABASE_PASSWORD=root123

REDIS_HOST=192.168.9.127
REDIS_PORT=6379
REDIS_DATABASE=1

正式环境启动示例(PowerShell):

$env:APP_ENV = "production"
$env:DATABASE_PASSWORD = "your-production-password"
go run ./cmd/server

运行

make run
# 或
go run ./cmd/server

健康检查

curl http://localhost:8080/api/v1/health

响应示例:

{
  "code": 0,
  "message": "ok",
  "data": {
    "status": "up"
  }
}

品牌列表

# 查询全部
curl "http://localhost:8080/audio/getBrand"

# 按名称模糊查询
curl "http://localhost:8080/audio/getBrand?brandName=sony"

添加新接口

  1. internal/handler/ 新建 handler
  2. internal/router/router.go/api/v1 分组下注册路由
  3. 使用 internal/response 返回统一格式

构建

make build
./bin/server
S
Description
No description provided
Readme 1.4 MiB
Languages
Go 92.7%
Shell 6.8%
Makefile 0.3%
Dockerfile 0.2%