2018-04-12 11:54:56 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2018-04-14 11:04:07 +00:00
|
|
|
"reflect"
|
|
|
|
|
|
|
|
cdr "git.loafle.net/commons/di-go/registry"
|
|
|
|
"git.loafle.net/commons/logging-go"
|
|
|
|
cur "git.loafle.net/commons/util-go/reflect"
|
2018-04-26 08:39:32 +00:00
|
|
|
occp "git.loafle.net/overflow/commons-go/config/probe"
|
2018-04-12 11:54:56 +00:00
|
|
|
)
|
|
|
|
|
2018-04-14 11:04:07 +00:00
|
|
|
const (
|
2018-04-18 14:56:13 +00:00
|
|
|
ConfigKey = "Config"
|
2018-04-14 11:04:07 +00:00
|
|
|
)
|
|
|
|
|
2018-04-12 11:54:56 +00:00
|
|
|
type Config struct {
|
2018-04-26 08:39:32 +00:00
|
|
|
Account *occp.Account `required:"true" json:"account" yaml:"account" toml:"account"`
|
|
|
|
Central *occp.Central `required:"true" json:"central" yaml:"central" toml:"central"`
|
|
|
|
Probe *occp.Probe `required:"true" json:"probe" yaml:"probe" toml:"probe"`
|
2018-04-12 11:54:56 +00:00
|
|
|
}
|
2018-04-14 11:04:07 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|