55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
cdr "git.loafle.net/commons/di-go/registry"
|
|
"git.loafle.net/commons/logging-go"
|
|
cur "git.loafle.net/commons/util-go/reflect"
|
|
ocpc "git.loafle.net/overflow/commons-go/probe/config"
|
|
)
|
|
|
|
const (
|
|
ConfigKey = "Config"
|
|
ConfigDirKey = "ConfigDir"
|
|
)
|
|
|
|
type Config struct {
|
|
Account *ocpc.Account `required:"true" json:"account" yaml:"account" toml:"account"`
|
|
Central *ocpc.Central `required:"true" json:"central" yaml:"central" toml:"central"`
|
|
Probe *ocpc.Probe `required:"true" json:"probe" yaml:"probe" toml:"probe"`
|
|
Paths map[string]string `required:"true" json:"paths" yaml:"paths" toml:"paths"`
|
|
}
|
|
|
|
func GetConfig() *Config {
|
|
_config, err := cdr.GetInstanceByName(ConfigKey)
|
|
if nil != err {
|
|
logging.Logger().Error(err)
|
|
return nil
|
|
}
|
|
config, ok := _config.(*Config)
|
|
if !ok {
|
|
_, pkg, n := cur.GetTypeInfo(reflect.TypeOf(_config))
|
|
logging.Logger().Errorf("Cannot convert [%s]%s to Config type", pkg, n)
|
|
return nil
|
|
}
|
|
|
|
return config
|
|
}
|
|
|
|
func GetConfigDir() string {
|
|
_configDir, err := cdr.GetInstanceByName(ConfigDirKey)
|
|
if nil != err {
|
|
logging.Logger().Error(err)
|
|
return ""
|
|
}
|
|
configDir, ok := _configDir.(string)
|
|
if !ok {
|
|
_, pkg, n := cur.GetTypeInfo(reflect.TypeOf(_configDir))
|
|
logging.Logger().Errorf("Cannot convert [%s]%s to string type", pkg, n)
|
|
return ""
|
|
}
|
|
|
|
return configDir
|
|
}
|