This commit is contained in:
2026-05-15 19:36:43 +08:00
parent 659054beb7
commit 085f59eb2b
7 changed files with 705 additions and 1 deletions
+31
View File
@@ -16,6 +16,7 @@ type Config struct {
Auth AuthConfig `yaml:"auth"`
Logging LoggingConfig `yaml:"logging"`
Database DatabaseConfig `yaml:"database"`
Admin AdminConfig `yaml:"admin"`
}
// ServerConfig MQTT 监听相关配置
@@ -68,6 +69,20 @@ type DatabaseConfig struct {
DSN string `yaml:"dsn"`
}
// AdminConfig HTTP 管理界面配置
type AdminConfig struct {
// 是否启用管理界面,默认 false
Enabled bool `yaml:"enabled"`
// HTTP 监听端口,留空则默认 :8080
Port string `yaml:"port"`
// 认证类型:none(默认) / basic / token(预留)
AuthType string `yaml:"auth_type"`
// Basic 认证用户名
Username string `yaml:"username"`
// Basic 认证密码
Password string `yaml:"password"`
}
// ---------------------------------------------------------------------------
// 全局单例
// ---------------------------------------------------------------------------
@@ -184,6 +199,15 @@ func applyDefaults(cfg *Config) bool {
cfg.Database.File = "meshgo.db"
changed = true
}
// Admin
if cfg.Admin.Port == "" {
cfg.Admin.Port = ":8080"
changed = true
}
if cfg.Admin.AuthType == "" {
cfg.Admin.AuthType = "none"
changed = true
}
return changed
}
@@ -211,5 +235,12 @@ func defaultConfig() *Config {
File: "meshgo.db",
DSN: "",
},
Admin: AdminConfig{
Enabled: false,
Port: ":8080",
AuthType: "none",
Username: "",
Password: "",
},
}
}