2024-11-22 16:41:04 +08:00
|
|
|
// Package config define config struct of wave record project
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"modelRT/constant"
|
|
|
|
|
"modelRT/log"
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// ModelRTConfig define config stuct of model runtime server
|
|
|
|
|
type ModelRTConfig struct {
|
2024-11-27 09:11:48 +08:00
|
|
|
GridID int64
|
|
|
|
|
ZoneID int64
|
|
|
|
|
StationID int64
|
2024-11-22 16:41:04 +08:00
|
|
|
ParseConcurrentQuantity int // parse comtrade file concurrent quantity
|
|
|
|
|
PostgresDBURI string
|
|
|
|
|
LCfg log.CutLogConfig // log config
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ReadAndInitConfig return wave record project config struct
|
|
|
|
|
func ReadAndInitConfig(configDir, configName, configType string) (modelRTConfig ModelRTConfig) {
|
|
|
|
|
config := viper.New()
|
|
|
|
|
config.AddConfigPath(configDir)
|
|
|
|
|
config.SetConfigName(configName)
|
|
|
|
|
config.SetConfigType(configType)
|
|
|
|
|
if err := config.ReadInConfig(); err != nil {
|
|
|
|
|
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
|
|
|
|
panic("can not find conifg file")
|
|
|
|
|
}
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// init postgresdb config from config.yaml
|
|
|
|
|
postgresDBHost := config.GetString("postgresdb_host")
|
|
|
|
|
postgresDBPort := config.GetInt("postgresdb_port")
|
|
|
|
|
postgresDBUser := config.GetString("postgresdb_user")
|
|
|
|
|
postgresDBPassword := config.GetString("postgresdb_password")
|
|
|
|
|
postgresDBDataBase := config.GetString("postgresdb_database")
|
|
|
|
|
modelRTConfig.PostgresDBURI = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s", postgresDBHost, postgresDBPort, postgresDBUser, postgresDBPassword, postgresDBDataBase)
|
|
|
|
|
// init zap log config from config.yaml
|
|
|
|
|
modelRTConfig.LCfg.Mode = config.GetString("log_mode")
|
|
|
|
|
modelRTConfig.LCfg.Level = config.GetString("log_level")
|
|
|
|
|
modelRTConfig.LCfg.FileName = fmt.Sprintf(config.GetString("log_filepath"), time.Now().Format(constant.LogTimeFormate))
|
|
|
|
|
modelRTConfig.LCfg.MaxSize = config.GetInt("log_maxsize")
|
|
|
|
|
modelRTConfig.LCfg.MaxBackups = config.GetInt("log_maxbackups")
|
|
|
|
|
modelRTConfig.LCfg.MaxAge = config.GetInt("log_maxage")
|
|
|
|
|
|
2024-11-27 09:11:48 +08:00
|
|
|
// init model base config from config.yaml
|
|
|
|
|
modelRTConfig.GridID = config.GetInt64("grid_id")
|
|
|
|
|
modelRTConfig.GridID = config.GetInt64("zone_id")
|
|
|
|
|
modelRTConfig.GridID = config.GetInt64("station_id")
|
2024-11-22 16:41:04 +08:00
|
|
|
modelRTConfig.ParseConcurrentQuantity = config.GetInt("parse_concurrent_quantity")
|
|
|
|
|
|
|
|
|
|
return modelRTConfig
|
|
|
|
|
}
|