feat():learning后台管理项目初始化
This commit is contained in:
47
internal/config/README.md
Normal file
47
internal/config/README.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# 配置管理
|
||||
|
||||
本模块负责管理应用程序的配置,支持从 YAML 文件加载配置。
|
||||
|
||||
## 功能特性
|
||||
|
||||
- 支持 YAML 配置文件
|
||||
- 配置热加载
|
||||
- 默认值设置
|
||||
- 类型安全的配置结构
|
||||
|
||||
## 配置结构
|
||||
|
||||
```yaml
|
||||
server:
|
||||
addr: "0.0.0.0"
|
||||
port: 8080
|
||||
|
||||
database:
|
||||
dsn: "user:password@tcp(localhost:3306)/goalfymax_admin?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
maxIdleConns: 10
|
||||
maxOpenConns: 100
|
||||
|
||||
admin:
|
||||
loginKey: "your-admin-password"
|
||||
jwtSecret: "your-jwt-secret"
|
||||
|
||||
log:
|
||||
level: "info"
|
||||
format: "json"
|
||||
output: "stdout"
|
||||
```
|
||||
|
||||
## 使用方法
|
||||
|
||||
```go
|
||||
// 加载配置
|
||||
err := config.LoadConfig("etc/config.yaml")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// 获取配置
|
||||
cfg := config.GetConfig()
|
||||
fmt.Println(cfg.Server.Addr)
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user