probe/config/config.go

55 lines
1.3 KiB
Go
Raw Normal View History

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-12 11:54:56 +00:00
ocpc "git.loafle.net/overflow/commons-go/probe/config"
)
2018-04-14 11:04:07 +00:00
const (
ConfigKey = "Config"
ConfigDirKey = "ConfigDir"
)
2018-04-12 11:54:56 +00:00
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"`
}
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
}
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
}