feat: 新增 MySQL 数据库驱动支持,支持跨设备数据同步
This commit is contained in:
21
README.md
21
README.md
@@ -66,7 +66,7 @@ nex/
|
||||
- **语言**: Go 1.26+
|
||||
- **HTTP 框架**: Gin
|
||||
- **ORM**: GORM
|
||||
- **数据库**: SQLite
|
||||
- **数据库**: SQLite / MySQL
|
||||
- **日志**: zap + lumberjack(结构化日志 + 日志轮转)
|
||||
- **配置**: Viper + pflag(多层配置:CLI > 环境变量 > 配置文件 > 默认值)
|
||||
- **验证**: go-playground/validator/v10
|
||||
@@ -204,7 +204,14 @@ server:
|
||||
write_timeout: 30s
|
||||
|
||||
database:
|
||||
path: ~/.nex/config.db
|
||||
driver: sqlite # sqlite 或 mysql
|
||||
path: ~/.nex/config.db # SQLite 数据库文件路径
|
||||
# --- MySQL 配置(driver=mysql 时生效)---
|
||||
# host: localhost
|
||||
# port: 3306
|
||||
# user: nex
|
||||
# password: ""
|
||||
# dbname: nex
|
||||
max_idle_conns: 10
|
||||
max_open_conns: 100
|
||||
conn_max_lifetime: 1h
|
||||
@@ -226,6 +233,14 @@ log:
|
||||
export NEX_SERVER_PORT=9000
|
||||
export NEX_DATABASE_PATH=/data/nex.db
|
||||
export NEX_LOG_LEVEL=debug
|
||||
|
||||
# MySQL 模式
|
||||
export NEX_DATABASE_DRIVER=mysql
|
||||
export NEX_DATABASE_HOST=db.example.com
|
||||
export NEX_DATABASE_PORT=3306
|
||||
export NEX_DATABASE_USER=nex
|
||||
export NEX_DATABASE_PASSWORD=secret
|
||||
export NEX_DATABASE_DBNAME=nex
|
||||
```
|
||||
|
||||
命名规则:配置路径转大写 + 下划线(如 `server.port` → `NEX_SERVER_PORT`)。
|
||||
@@ -241,7 +256,7 @@ export NEX_LOG_LEVEL=debug
|
||||
### 数据文件
|
||||
|
||||
- `~/.nex/config.yaml` - 配置文件
|
||||
- `~/.nex/config.db` - SQLite 数据库
|
||||
- `~/.nex/config.db` - SQLite 数据库(MySQL 模式下不使用本地数据库文件)
|
||||
- `~/.nex/log/` - 日志目录
|
||||
|
||||
## 测试
|
||||
|
||||
Reference in New Issue
Block a user