You've already forked VptPassiveAdapter
Initial
This commit is contained in:
34
config/dto.go
Normal file
34
config/dto.go
Normal file
@ -0,0 +1,34 @@
|
||||
package config
|
||||
|
||||
type ApiConfig struct {
|
||||
BaseUrl string `mapstructure:"baseUrl"`
|
||||
}
|
||||
|
||||
type RecordConfig struct {
|
||||
Storage StorageConfig `mapstructure:"storage"`
|
||||
Duration int `mapstructure:"duration"`
|
||||
}
|
||||
|
||||
type StorageConfig struct {
|
||||
Type string `mapstructure:"type"`
|
||||
Path string `mapstructure:"path"`
|
||||
}
|
||||
|
||||
type DeviceMapping struct {
|
||||
DeviceNo string `mapstructure:"deviceNo" json:"deviceNo"`
|
||||
Name string `mapstructure:"name" json:"name"`
|
||||
}
|
||||
|
||||
type FileNameConfig struct {
|
||||
DateSeparator string `mapstructure:"dateSeparator"`
|
||||
TimeSplit string `mapstructure:"timeSplit"`
|
||||
FileExt string `mapstructure:"fileExt"`
|
||||
UnfinishedFileExt string `mapstructure:"unFinExt"`
|
||||
}
|
||||
|
||||
type MainConfig struct {
|
||||
Api ApiConfig `mapstructure:"api"`
|
||||
Record RecordConfig `mapstructure:"record"`
|
||||
Devices []DeviceMapping `mapstructure:"devices"`
|
||||
FileName FileNameConfig `mapstructure:"fileName"`
|
||||
}
|
27
config/service.go
Normal file
27
config/service.go
Normal file
@ -0,0 +1,27 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
"log"
|
||||
)
|
||||
|
||||
var Config MainConfig
|
||||
|
||||
func LoadConfig() error {
|
||||
viper.SetConfigName("config")
|
||||
viper.SetConfigType("yaml")
|
||||
viper.AddConfigPath(".")
|
||||
|
||||
// 读取配置文件
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
log.Fatalf("Error reading config file, %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// 反序列化配置到结构体
|
||||
if err := viper.Unmarshal(&Config); err != nil {
|
||||
log.Fatalf("Unable to decode into struct, %v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user