package conf import ( "path/filepath" "time" ) type Bootstrap struct { Debug bool `toml:"-" json:"-"` BuildVersion string `toml:"-" json:"-"` ConfigDir string `toml:"-" json:"-"` ConfigPath string `toml:"-" json:"-"` Server Server // 服务器 Data Data // 数据 Plugin Plugin VqdConfig VqdConfig // 诊断基础配置 VqdLgtDark VqdLgtDark // 亮度检测 VqdBlue VqdBlue // 蓝屏检查 VqdClarity VqdClarity // 清晰度检查 VqdShark VqdShark // 抖动检查 VqdFreeze VqdFreeze // 冻结检测 VqdColor VqdColor // 偏色检测 VqdOcclusion VqdOcclusion // 遮挡检测 VqdNoise VqdNoise // 噪声检测 VqdContrast VqdContrast // 对比度检测 VqdMosaic VqdMosaic // 马赛克检测 VqdFlower VqdFlower // 花屏检测 Log Log // 日志 } type Plugin struct { HttpAPI string `json:"http_api" comment:"http 地址"` // Enable bool `json:"enable" comment:"是否开启"` GrpcPort int `json:"port" comment:"通信端口"` AllDebug bool `json:"all_debug" comment:"是否开启"` } type Server struct { HTTP ServerHTTP `comment:"对外提供的服务,建议由 nginx 代理"` // HTTP服务器 } type ServerHTTP struct { Port int `comment:"http 端口"` // 服务器端口号 Timeout Duration `comment:"请求超时时间"` // 请求超时时间 JwtSecret string `comment:"jwt 秘钥,空串时,每次启动程序将随机赋值"` // JWT密钥 PProf ServerPPROF // Pprof配置 } // ServerPPROF 结构体,包含 Enabled 和 AccessIps 两个字段 type ServerPPROF struct { Enabled bool `comment:"是否启用 pprof, 建议设置为 true"` // 是否启用 AccessIps []string `comment:"访问白名单" json:"access_ips"` // 允许访问的IP地址列表 } // Data 结构体,包含 Database 和 Redis 两个字段 type Data struct { // Database 数据库 Database Database `comment:"数据库支持 sqlite 和 postgres 两种,使用 sqlite 时 dsn 应当填写文件存储路径"` // Redis Redis数据库 // Redis DataRedis } // Database 结构体,包含 Dsn、MaxIdleConns、MaxOpenConns、ConnMaxLifetime 和 SlowThreshold 五个字段 type Database struct { Dsn string // 数据源名称 MaxIdleConns int32 // 最大空闲连接数 MaxOpenConns int32 // 最大打开连接数 ConnMaxLifetime Duration // 连接最大生命周期 SlowThreshold Duration // 慢查询阈值 } // Log 结构体,包含 Dir、Level、MaxAge、RotationTime 和 RotationSize 五个字段 type Log struct { Dir string `comment:"日志存储目录,不能使用特殊符号"` Level string `comment:"记录级别 debug/info/warn/error"` MaxAge Duration `comment:"保留日志多久,超过时间自动删除"` RotationTime Duration `comment:"多久时间,分割一个新的日志文件"` RotationSize int64 `comment:"多大文件,分割一个新的日志文件(MB)"` } func (s *Bootstrap) ConfigDirPath() string { return filepath.Join(s.ConfigDir, "config.toml") } type Duration time.Duration func (d *Duration) UnmarshalText(b []byte) error { x, err := time.ParseDuration(string(b)) if err != nil { return err } *d = Duration(x) return nil } func (d Duration) MarshalText() ([]byte, error) { return []byte(d.Duration().String()), nil } func (d *Duration) Duration() time.Duration { return time.Duration(*d) } // 基础配置 type VqdConfig struct { SaveDay int32 `json:"save_day" comment:"数据保存天数"` FrmNum int32 `json:"frm_num" comment:"连续分析帧数(2-64), 默认为10, 最大为 64"` IsDeepLearn bool `json:"is_deep_learn" comment:"是否使用深度学习版本, 默认使用深度学习版本"` } // 亮度检测 type VqdLgtDark struct { DarkThr float64 `json:"dark_thr" comment:"默认 0.4, 取值范围: 0~1, 建议范围: 0.2~0.6"` LgtThr float64 `json:"lgt_thr" comment:"默认 0.1, 取值范围: 0~1, 建议范围: 0.1~0.5"` LgtDarkAbnNumRatio float64 `json:"lgt_dark_abn_num_ratio" comment:"默认为0.5, 取值范围: 0~1, 建议范围: 0.1~0.9"` } // 蓝屏检查 type VqdBlue struct { BlueThr float64 `json:"blue_thr" comment:"默认为 0.6, 取值范围: 0~1, 建议范围 0.4~0.9"` BlueAbnNumRatio float64 `json:"blue_abn_num_ratio" comment:"默认为0.5, 取值范围: 0~1, 建议范围: 0.1~0.9"` } // 清晰度检查 type VqdClarity struct { ClarityThr float64 `json:"clarity_thr" comment:"默认为0.4, 取值范围: 0~1, 建议范围: 0.3~0.99"` ClarityAbnNumRatio float64 `json:"clarity_abn_num_ratio" comment:"默认为0.5, 取值范围: 0~1, 建议范围: 0.1~0.9"` } // 抖动检查 type VqdShark struct { SharkThr float64 `json:"shark_thr" comment:"默认为 0.2, 取值范围: 0~1, 建议范围: 0.1~0.8"` SharkAbnNumRatio float64 `json:"shark_abn_num_ratio" comment:"默认为0.2, 取值范围: 0~1, 建议范围: 0.1~0.6"` } // 冻结检测 type VqdFreeze struct { FreezeThr float64 `json:"freeze_thr" comment:"默认 0.4, 取值范围: 0~1, 建议范围: 0.2~0.6"` FreezeAbnNumRatio float64 `json:"freeze_abn_num_ratio" comment:"默认为0.99, 取值范围: 0.8~1, 建议范围: 0.95~1"` } // 偏色检测 type VqdColor struct { ColorThr float64 `json:"color_thr" comment:"默认为0.18, 取值范围: 0~1, 建议范围: 0.1~0.5"` ColorAbnNumRatio float64 `json:"color_abn_num_ratio" comment:"默认为0.5, 取值范围: 0~1, 建议范围: 0.3~0.9"` } // 遮挡检测 type VqdOcclusion struct { OcclusionThr float64 `json:"occlusion_thr" comment:"默认为0.1, 取值范围: 0~1, 建议范围: 0.05~0.5"` OcclusionAbnNumRatio float64 `json:"occlusion_abn_num_ratio" comment:"默认为0.5, 取值范围: 0~1, 建议范围: 0.3~0.9"` } // 噪声检测 type VqdNoise struct { NoiseThr float64 `json:"noise_thr" comment:"默认为 0.3, 取值范围: 0~1, 建议范围: 0.2~0.8"` NoiseAbnNumRatio float64 `json:"noise_abn_num_ratio" comment:"默认为0.6, 取值范围: 0~1, 建议范围: 0.3~0.9"` } // 对比度检测 type VqdContrast struct { CtraLowThr float64 `json:"ctra_low_thr" comment:"默认为 0.2, 取值范围: 0~1, 建议范围: 0.1~0.3"` CtraHighThr float64 `json:"ctra_high_thr" comment:"默认为 0.8, 取值范围: 0~1, 建议范围: 0.7~0.9"` CtraAbnNumRatio float64 `json:"ctra_abn_num_ratio" comment:"默认为0.5, 取值范围: 0~1, 建议范围: 0.3~0.9"` } // 马赛克检测 type VqdMosaic struct { MosaicThr float64 `json:"mosaic_thr" comment:"默认为 0.1 取值范围: 0~1, 建议范围: 0.1~0.9"` MosaicAbnNumRatio float64 `json:"mosaic_abn_num_ratio" comment:"默认为0.5,取值范围: 0~1, 建议范围: 0.3"` } // 花屏检测 type VqdFlower struct { FlowerThr float64 `json:"flower_thr" comment:"默认为 0.3 取值范围: 0~1, 建议范围: 0.1~0.9"` FlowerAbnNumRatio float64 `json:"flower_abn_num_ratio" comment:"默认为0.6, 取值范围: 0~1, 建议范围: 0.3"` MosaicThr float64 `json:"mosaic_thr" comment:"默认为 0.3 取值范围: 0~1, 建议范围: 0.1~0.9"` }