123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- package conf
- import (
- "errors"
- "flag"
- "go-common/app/admin/ep/melloi/model"
- "go-common/library/cache/memcache"
- "go-common/library/cache/redis"
- "go-common/library/conf"
- "go-common/library/database/orm"
- ecode "go-common/library/ecode/tip"
- "go-common/library/log"
- bm "go-common/library/net/http/blademaster"
- "go-common/library/net/http/blademaster/middleware/permit"
- "go-common/library/net/rpc/warden"
- "go-common/library/net/trace"
- "github.com/BurntSushi/toml"
- )
- var (
- confPath string
- client *conf.Client
-
- Conf = &Config{}
- )
- type Config struct {
- Log *log.Config
-
- Tracer *trace.Config
- Redis *redis.Config
- Memcache *memcache.Config
- Ecode *ecode.Config
- ORM *orm.Config
- Permit *permit.Config2
- PermitGRPC *warden.ClientConfig
- HTTPClient *bm.ClientConfig
- ServiceTree *model.TreeConf
- Dapper *Dapper
- BfsConf *model.BFSConf
- ServiceCluster *model.ClusterConf
- Melloi *Melloi
- BM *bm.ServerConfig
- Wechat *Wechat
- Mail *Mail
- Paas *Paas
- Grpc *Grpc
- Jmeter *Jmeter
- DockerStatus *DockerStatus
- }
- type Dapper struct {
- Host string
- }
- type DockerStatus struct {
- Host string
- Port int
- }
- type Paas struct {
- APIToken string
- PlatformID string
- BusinessUnit string
- Project string
- App string
- Env string
- Image string
- ImageVersion string
- Volumes string
- ResourcePoolID string
- Completions int
- RetriesLimit int
- NetworkID int
- ClusterID int
- TreeID int
- HostInfo string
- Action string
- PublicKey string
- Signature int
- DataSource string
- Query string
- CPUCore int
- CPUCoreDebug int
- }
- type Melloi struct {
- AppkeyProd string
- SecretProd string
- AppkeyUat string
- SecretUat string
- Executor []string
- CheckTime bool
- MaxFileSize int64
- DefaultHost string
- MaxDowloadSize int64
- DefaultFusing int
- DefaultBusinessRate int
- Recent int
- }
- type Wechat struct {
- Host string
- Chatid string
- Msgtype string
- Safe int
- SendMessage bool
- }
- type Mail struct {
- Host string
- Port int
- Username string
- Password string
- NoticeOwner []string
- }
- type Grpc struct {
- ProtoJavaPluginPath string
- }
- type Jmeter struct {
- JmeterExtLibPath string
- JmeterExtLibPathContainer string
- GRPCTemplatePath string
- TestTimeLimit int
- ThreadGroupPort int
- JmeterScUcodedTmp string
- JmeterScTmp string
- JmeterSampleTmp string
- JmeterSamplePostTmp string
- JmeterThGroupTmp string
- JmeterThGroupPostTmp string
- JmeterThGroupDuliTmp string
- JmeterThGroupPostDuliTmp string
- JmeterSceneTmp string
- JSONExtractorTmp string
- }
- func init() {
- flag.StringVar(&confPath, "conf", "", "default config path")
- }
- func Init() error {
- if confPath != "" {
- return local()
- }
- return remote()
- }
- func local() (err error) {
- _, err = toml.DecodeFile(confPath, &Conf)
- return
- }
- func remote() (err error) {
- if client, err = conf.New(); err != nil {
- return
- }
- return load()
- }
- func load() (err error) {
- var (
- s string
- ok bool
- tmpConf *Config
- )
- if s, ok = client.Value("melloi.toml"); !ok {
- return errors.New("load config center error")
- }
- if _, err = toml.Decode(s, &tmpConf); err != nil {
- return errors.New("could not decode config")
- }
- *Conf = *tmpConf
- return
- }
|