package config
|
|
import (
|
"basic.com/valib/logger.git"
|
"github.com/fsnotify/fsnotify"
|
"log"
|
|
"github.com/spf13/viper"
|
)
|
|
type server struct {
|
ServerName string `mapstructure:"serverName"`
|
Runmode string `mapstructure:"runmode"`
|
JwtSecret string `mapstructure:"jwtSecret"`
|
JwtExpire string `mapstructure:"jwtExpire"`
|
Url string `mapstructure:"url"`
|
AnalyServerId string `mapstructure:"analyServerId"`
|
NetworkAdapter string `mapstructure:"networkAdapter"`
|
|
DeviceNum string `mapstructure:"deviceNum"` //设备编号
|
DeviceType string `mapstructure:"deviceType"` //设备类型
|
DeviceModel string `mapstructure:"deviceModel"` //设备型号
|
DeviceSerialNum string `mapstructure:"deviceSerialNum"` //设备序列号
|
DeviceDesc string `mapstructure:"deviceDesc"` //设备描述
|
MasterVersion string `mapstructure:"masterVersion"` //主控版本
|
WebVersion string `mapstructure:"webVersion"` //web版本
|
ChannelCount string `mapstructure:"channelCount"` //通道个数
|
DiskCount string `mapstructure:"diskCount"` //硬盘个数
|
LicensePath string `mapstructure:"licensePath"` //license文件位置
|
LKey string `mapstructure:"lKey"`
|
LPublicKeyPath string `mapstructure:"lPublicKeyPath"`
|
|
SudoPassword string `mapstructure:"sudoPassword"` //系统密码
|
SysThresholds []threshold `mapstructure:"sysThresholds"`
|
PTZSpeed int `mapstructure:"ptzSpeed"` // 云台移动速度
|
PatchPath string `mapstructure:"patchPath"` //系统更新包路径
|
BakPath string `mapstructure:"bakPath"` //系统更新包路径
|
Voices []Voice `mapstructure:"voices"`
|
GbWaitSec int `mapstructure:"gbWaitSec"` //国标刷新后,请求等待时间
|
GbCamCount int `mapstructure:"gbCamCount"` //国标可配置摄像机数量
|
RtspUnique bool `mapstructure:"rtspUnique"` //false:允许单机rtsp重复,为true时不允许单机上rtsp重复
|
|
Resolutions []resolution `mapstructure:"resolutions"` //数据栈可用的分辨率
|
HeadPics []string `mapstructure:"headpics"` //默认头像列表
|
Langs []lang `mapstructure:"langs"` //语言
|
}
|
|
type threshold struct {
|
Value int `mapstructure:"value"`
|
Color string `mapstructure:"color"`
|
}
|
|
type Voice struct {
|
Id string `mapstructure:"id"`
|
Name string `mapstructure:"name"`
|
Path string `mapstructure:"path"`
|
}
|
|
type resolution struct {
|
Width int `mapstructure:"width"`
|
Height int `mapstructure:"height"`
|
}
|
|
type lang struct {
|
Name string `mapstructure:"name"`
|
Lang string `mapstructure:"lang"`
|
Language string `mapstructure:"language"`
|
}
|
|
var Server = &server{}
|
|
type database struct {
|
Driver string `mapstructure:"driver"`
|
Name string `mapstructure:"name"`
|
FilePath string `mapstructure:"filepath"`
|
}
|
|
var DBconf = &database{}
|
|
type TraceConfig struct {
|
UseBlockList int `mapstructure:"useBlockList"`
|
}
|
|
var Traceconf = &TraceConfig{}
|
|
type dbpersoncompare struct {
|
Ip string `mapstructure:"ip"`
|
Port int `mapstructure:"port"`
|
}
|
|
type cluster struct {
|
PwdPre string `mapstructure:"pwdpre"`
|
SerfSnapShotPath string `mapstructure:"serfsnapshotpath"`
|
Port int `mapstructure:"port"`
|
HeartBeat int `mapstructure:"heartBeat"`
|
SaasReportUrl string `mapstructure:"saasReportUrl"`
|
}
|
|
var ClusterSet = &cluster{}
|
|
type esinfo struct {
|
Port int `mapstructure:"port"`
|
Shards string `mapstructure:"shards"`
|
EsIndex esindexlist `mapstructure:"index"`
|
StorePath []string `mapstructure:"storePath"`
|
ThresholdTime int `mapstructure:"thresholdTime"`
|
ThresholdStayTime int `mapstructure:"thresholdStayTime"`
|
}
|
|
type esindexlist struct {
|
AiOcean index `mapstructure:"aiocean"`
|
}
|
type index struct {
|
IndexName string `mapstructure:"index"`
|
IndexType string `mapstructure:"type"`
|
}
|
|
type weedfs struct {
|
Port int `mapstructure:"port"`
|
}
|
|
type facedetect struct {
|
Ip string `mapstructure:"Ip"`
|
Port int `mapstructure:"port"`
|
}
|
|
type espersoncompare struct {
|
Port int `mapstructure:"port"`
|
Ips []string `mapstructure:"ips"`
|
}
|
|
type storageConfig struct {
|
VolumePath []string `mapstructure:"volumePath"`
|
}
|
|
var StorageConf = &storageConfig{}
|
|
var DbPersonCompare = &dbpersoncompare{}
|
|
var EsCompServerInfo = &espersoncompare{}
|
|
var FaceDetectSet = &facedetect{}
|
|
var EsConfig = &esinfo{}
|
|
var WeedFs = &weedfs{}
|
|
var EsInfo = &esinfo{}
|
|
type elastic struct {
|
IndexName string `mapstructure:"indexName"`
|
IndexType string `mapstructure:"indexType"`
|
}
|
|
var BasicFS = &elastic{}
|
|
type logConfig struct {
|
Path string `mapstructure:"path"` //日志存储路径
|
Level int `mapstructure:"level"` //日志等级
|
MaxSize int `mapstructure:"maxSize"` //日志文件大小上限
|
MaxBackups int `mapstructure:"maxBackups"` //日志压缩包个数
|
MaxAge int `mapstructure:"maxAge"` //保留压缩包天数
|
}
|
|
var LogConf = &logConfig{}
|
|
type shop struct {
|
Url string `mapstructure:"url"`
|
LocalShop string `mapstructure:"localShop"` //本地商城地址
|
SysDomains []string `mapstructure:"sysDomains"` //系统升级的域名列表
|
}
|
|
var ShopConf = &shop{}
|
|
type saas struct {
|
Url string `mapstructure:"url"`
|
}
|
|
var SaasConf = &saas{}
|
|
type pushSetMenu struct {
|
Id string `mapstructure:"id" json:"id"`
|
Name string `mapstructure:"name" json:"name"`
|
Checked bool `mapstructure:"checked" json:"checked"`
|
Alias string `mapstructure:"alias" json:"alias"`
|
Children []pushSetMenu `mapstructure:"children" json:"children"`
|
}
|
|
var PushSet = make([]pushSetMenu, 0)
|
|
// Init is an exported method that takes the environment starts the viper
|
// (external lib) and returns the configuration struct.
|
func Init(env string) {
|
var err error
|
v := viper.New()
|
v.SetConfigType("yaml")
|
v.SetConfigName(env)
|
v.AddConfigPath("../config/")
|
v.AddConfigPath("./config/")
|
err = v.ReadInConfig()
|
if err != nil {
|
log.Fatal("error on parsing configuration file")
|
}
|
read2Conf(v)
|
v.WatchConfig()
|
v.OnConfigChange(func(in fsnotify.Event) {
|
read2Conf(v)
|
})
|
}
|
|
func read2Conf(v *viper.Viper) {
|
v.UnmarshalKey("es", EsInfo)
|
v.UnmarshalKey("server", Server)
|
v.UnmarshalKey("database", DBconf)
|
v.UnmarshalKey("trace", Traceconf)
|
|
v.UnmarshalKey("facedetect", FaceDetectSet)
|
v.UnmarshalKey("dbpersoncompare", DbPersonCompare)
|
v.UnmarshalKey("espersoncompare", EsCompServerInfo)
|
v.UnmarshalKey("elastic.basicFS", BasicFS)
|
v.UnmarshalKey("shop", ShopConf)
|
v.UnmarshalKey("saas", SaasConf)
|
v.UnmarshalKey("thresholdTime", EsInfo.ThresholdTime)
|
v.UnmarshalKey("thresholdTime", EsInfo.ThresholdStayTime)
|
v.UnmarshalKey("cluster", ClusterSet)
|
v.UnmarshalKey("es", EsConfig)
|
v.UnmarshalKey("weedfs", WeedFs)
|
v.UnmarshalKey("log", LogConf)
|
v.UnmarshalKey("storage", StorageConf)
|
v.UnmarshalKey("pushSet", &PushSet)
|
logger.SetLevel(LogConf.Level)
|
}
|