You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

76 lines
2.8 KiB

package console
import (
"yunyan/lego/utils/mapstructure"
"yunyan/modules"
)
// Options console 模块配置,对应 yaml 的 modules.console。
type Options struct {
modules.Options
HTTP HTTPConf
StaticDir string // console 独立精简前端目录,默认 ./consoleweb
TokenKey string // JWT 签名密钥(登录签发 + 鉴权校验)
AdminAccount string // 超管账号(第一期仅超管 + token)
AdminPassword string // 超管密码
SiteName string // 控制面站点名称(前端顶栏显示)
// EncryptKey 依赖服务(svcconfig)加密字段的 AES-256-GCM 主密钥
// (建议从 ${FIELD_ENCRYPT_KEY} 环境变量注入;生产必须覆盖默认值)。
EncryptKey string
// SkipEnsureTables 为 true 时,新建应用连接后不对其设备库跑建表(AutoMigrate)。
// 指向已存在表结构的生产库(如 Supabase)时打开,避免 console 改动其 schema;只读查看场景安全。
SkipEnsureTables bool
// Stat 统计汇总管道配置(消费 analyze 双写到 NATS 的埋点事件,落 stats_global_day)。
Stat StatConf
}
type HTTPConf struct {
Addr string // HTTP 监听地址,如 ":8080"
}
// StatConf 统计汇总管道配置,对应 yaml 的 modules.console.Stat。
type StatConf struct {
Subject string // 订阅的 NATS subject,需与各 analyze 的 modules.analyze.Subject 一致;为空则不启用消费
Stream string // JetStream 流名(不存在则自动创建,捕获 Subject)
Durable string // 持久消费者名(断线/重启续传;快照为绝对值,重放幂等)
Timezone string // 统计日界时区,默认 Asia/Shanghai;须与各 analyze 端一致,决定 0 点切日口径
// RecvLogCap 「统计日志」面板每天保留的快照接收记录条数上限(按接收时间分天存 Redis,
// 仅留最新 N 条,供后台核对每天汇报数据是否正常进来)。默认 2000,<=0 时回退默认。
RecvLogCap int
}
func (this *Options) LoadConfig(settings map[string]interface{}) (err error) {
if settings != nil {
if err = this.Options.LoadConfig(settings); err != nil {
return
}
if err = mapstructure.Decode(settings, this); err != nil {
return
}
}
if this.HTTP.Addr == "" {
this.HTTP.Addr = ":8080"
}
if this.StaticDir == "" {
this.StaticDir = "./consoleweb"
}
if this.TokenKey == "" {
this.TokenKey = "console-default-token-key"
}
if this.SiteName == "" {
this.SiteName = "Console"
}
if this.EncryptKey == "" {
this.EncryptKey = "console-default-encrypt-key-xxxxx!" // 生产必须通过 ${FIELD_ENCRYPT_KEY} 覆盖
}
if this.Stat.Stream == "" {
this.Stat.Stream = "STATS"
}
if this.Stat.Durable == "" {
this.Stat.Durable = "console-stats"
}
if this.Stat.RecvLogCap <= 0 {
this.Stat.RecvLogCap = 2000
}
return
}