package config
|
|
import (
|
"log"
|
"github.com/spf13/viper"
|
)
|
|
type Db struct {
|
User string `mapstructure:"user"`
|
Shop string `mapstructure:"shop"`
|
Device string `mapstructure:"device"`
|
Log string `mapstructure:"log"`
|
}
|
|
type LogConfig struct {
|
Path string `mapstructure:"path"`
|
Level int `mapstructure:"level"`
|
}
|
|
type ServiceConfig struct {
|
User string `mapstructure:"user"`
|
Shop string `mapstructure:"shop"`
|
Device string `mapstructure:"device"`
|
Log string `mapstructure:"log"`
|
Version string `mapstructure:"latest"`
|
}
|
|
type RegistryConfig struct {
|
Addrs []string `mapstructure:"addrs"`
|
}
|
|
type BrokerConfig struct {
|
Addrs []string `mapstructure:"addrs"`
|
}
|
|
type TraceConfig struct {
|
Addr string `mapstructure:"addr"`
|
}
|
|
type RedisConfig struct {
|
Ip string `mapstructure:"ip"`
|
Port int `mapstructure:"port"`
|
}
|
|
var DbConf = &Db{}
|
var LogConf = &LogConfig{}
|
var ServiceConf = &ServiceConfig{}
|
var RegistryConf = &RegistryConfig{}
|
var BrokerConf = &BrokerConfig{}
|
var TracingConf = &TraceConfig{}
|
var RedisConf = &RedisConfig{}
|
|
func init() {
|
var err error
|
viper.SetConfigType("yaml")
|
viper.SetConfigName("config")
|
viper.AddConfigPath("./config/")
|
err = viper.ReadInConfig()
|
if err != nil {
|
log.Fatal("error on parsing configuration file:", err)
|
}
|
viper.UnmarshalKey("db", DbConf)
|
viper.UnmarshalKey("log", LogConf)
|
viper.UnmarshalKey("service", ServiceConf)
|
viper.UnmarshalKey("registry", RegistryConf)
|
viper.UnmarshalKey("broker", BrokerConf)
|
viper.UnmarshalKey("trace", TracingConf)
|
viper.UnmarshalKey("redis", RedisConf)
|
}
|