dataRT/config/config.go

117 lines
2.3 KiB
Go

package config
import (
_ "embed"
"encoding/json"
)
type config struct {
serverConf *serverConfig
logConf *logConfig
postgresConf map[string]*postgresConfig
influxConf map[string]*influxConfig
redisConf map[string]*redisConfig
modelrtConf map[string]*modelrtConfig
}
//go:embed server.json
var serverjson string
//go:embed log.json
var logjson string
//go:embed postgres.json
var postgresjson string
//go:embed influx.json
var influxjson string
//go:embed redis.json
var redisjson string
//go:embed modelrt.json
var modelrtjson string
var conf *config
func init() {
conf = new(config)
conf.serverConf = new(serverConfig)
conf.logConf = new(logConfig)
conf.postgresConf = make(map[string]*postgresConfig)
conf.influxConf = make(map[string]*influxConfig)
conf.redisConf = make(map[string]*redisConfig)
conf.modelrtConf = make(map[string]*modelrtConfig)
err := json.Unmarshal([]byte(serverjson), conf.serverConf)
if err != nil {
panic(err.Error())
}
err = json.Unmarshal([]byte(logjson), conf.logConf)
if err != nil {
panic(err.Error())
}
err = json.Unmarshal([]byte(postgresjson), &conf.postgresConf)
if err != nil {
panic(err.Error())
}
err = json.Unmarshal([]byte(influxjson), &conf.influxConf)
if err != nil {
panic(err.Error())
}
err = json.Unmarshal([]byte(redisjson), &conf.redisConf)
if err != nil {
panic(err.Error())
}
err = json.Unmarshal([]byte(modelrtjson), &conf.modelrtConf)
if err != nil {
panic(err.Error())
}
}
func Conf() *config {
return conf
}
func (c *config) ServerConf() *serverConfig {
if c == nil {
panic("config is nil")
}
return c.serverConf
}
func (c *config) LogConf() *logConfig {
if c == nil {
panic("config is nil")
}
return c.logConf
}
func (c *config) PostgresConf(tag string) *postgresConfig {
if c == nil || c.postgresConf == nil {
panic("postgres config is nil")
}
return c.postgresConf[tag]
}
func (c *config) InfluxConf(tag string) *influxConfig {
if c == nil || c.influxConf == nil {
panic("influx config is nil")
}
return c.influxConf[tag]
}
func (c *config) RedisConf(tag string) *redisConfig {
if c == nil || c.redisConf == nil {
panic("redis config is nil")
}
return c.redisConf[tag]
}
func (c *config) ModelRTConf(tag string) *modelrtConfig {
if c == nil {
panic("modelrt config is nil")
}
return c.modelrtConf[tag]
}