package main import ( "f5" "mt" "sync" ) const ( MT_SERVER_INFO = 0 MT_ALI_KEY = iota MT_TX_KEY MT_SCENE_WHITE_LIST MT_LAUNCH_WHITE_LIST MT_BLOCK_PROVINCE_CITY MT_MAX ) type MetaMgr struct { f5.MetaMgr txKey string txSecretKey string accessKeyId string accessSecret string sdkInfoMutex sync.RWMutex fixedBlockRegionHash map[string]int32 fixedBlockRegionHashMutex sync.RWMutex } func (this *MetaMgr) Init() *MetaMgr { this.MetaMgr.Init() configDir := "../config/" if !f5.IsOnlineEnv() { configDir = "/var/data/conf_test/analyseapi/" } metaClasses := &[]f5.MetaClass{ f5.MetaClass{ PrimKey: "InstanceId", FileName: configDir + "analyseapi.cluster.json", Idx: MT_SERVER_INFO, RawMeta: (*mt.ServerInfoMetas)(nil), WrapMeta: (*MtwServerInfo)(nil)}, f5.MetaClass{ FileName: configDir + "ali_key.json", Idx: MT_ALI_KEY, RawMeta: (*mt.AliKeyInfoMetas)(nil), WrapMeta: (*MtwAliKeyConf)(nil)}, f5.MetaClass{ FileName: configDir + "tx_key.json", Idx: MT_TX_KEY, RawMeta: (*mt.TxKeyInfoMetas)(nil), WrapMeta: (*MtwTxKeyConf)(nil)}, f5.MetaClass{ FileName: configDir + "scene_whitelist.json", Idx: MT_SCENE_WHITE_LIST, RawMeta: (*mt.SceneWhiteListMetas)(nil), WrapMeta: (*MtwSceneWhiteList)(nil)}, f5.MetaClass{ FileName: configDir + "launch_whitelist.json", Idx: MT_LAUNCH_WHITE_LIST, RawMeta: (*mt.LaunchWhiteListMetas)(nil), WrapMeta: (*MtwLaunchWhiteList)(nil)}, f5.MetaClass{ FileName: configDir + "block_province_city.json", Idx: MT_BLOCK_PROVINCE_CITY, RawMeta: (*mt.BlockProvinceCityMetas)(nil), WrapMeta: (*MtwBlockProvinceCity)(nil)}, } this.MetaMgr.RegisterMetaClasses(metaClasses) this.Load() this.secondInit() return this } func (this *MetaMgr) UnInit() { this.MetaMgr.UnInit() } func (this *MetaMgr) secondInit() { this.sdkInfoMutex.Lock() this.fixedBlockRegionHashMutex.Lock() defer this.sdkInfoMutex.Unlock() defer this.fixedBlockRegionHashMutex.Unlock() this.txKey = this.GetTxKey().GetKey() this.txSecretKey = this.GetTxKey().GetSecretKey() this.accessKeyId = this.GetAliKey().GetAccessKeyid() this.accessSecret = this.GetAliKey().GetAccessSecret() this.fixedBlockRegionHash = make(map[string]int32) for _, val := range this.GetFixedBlockRegion().GetList() { this.fixedBlockRegionHash[val] = 1 } } func (this *MetaMgr) GetServer(instance_id int32) *MtwServerInfo { v, ok := this.MetaMgr.GetMetaById(MT_SERVER_INFO, instance_id).(*MtwServerInfo) if ok { return v } else { return nil } } func (this *MetaMgr) GetCurrServer() *MtwServerInfo { return this.GetServer(int32(f5.App.GetInstanceId())) } func (this *MetaMgr) GetAliKey() *MtwAliKeyConf { v, ok := this.MetaMgr.GetMetaById(MT_ALI_KEY, 1).(*MtwAliKeyConf) if ok { return v } else { return nil } } func (this *MetaMgr) GetTxKey() *MtwTxKeyConf { v, ok := this.MetaMgr.GetMetaById(MT_TX_KEY, 1).(*MtwTxKeyConf) if ok { return v } else { return nil } } func (this *MetaMgr) GetSceneWhiteList() *MtwSceneWhiteList { v, ok := this.MetaMgr.GetMetaById(MT_SCENE_WHITE_LIST, 1).(*MtwSceneWhiteList) if ok { return v } else { return nil } } func (this *MetaMgr) GetLaunchWhiteList() *MtwLaunchWhiteList { v, ok := this.MetaMgr.GetMetaById(MT_LAUNCH_WHITE_LIST, 1).(*MtwLaunchWhiteList) if ok { return v } else { return nil } } func (this *MetaMgr) GetFixedBlockRegion() *MtwBlockProvinceCity { v, ok := this.MetaMgr.GetMetaById(MT_BLOCK_PROVINCE_CITY, 1).(*MtwBlockProvinceCity) if ok { return v } else { return nil } } func (this* MetaMgr) GetAliSdkInfo(accessKeyId* string, accessSecret* string) { this.sdkInfoMutex.Lock() defer this.sdkInfoMutex.Unlock() *accessKeyId = "" + this.accessKeyId *accessSecret = "" + this.accessSecret } func (this* MetaMgr) GetTxSdkInfo(txKey* string, secretKey* string) { this.sdkInfoMutex.Lock() defer this.sdkInfoMutex.Unlock() *txKey = "" + this.txKey *secretKey = "" + this.txSecretKey } func (this* MetaMgr) IsBlockZone(country string, province string, city string) bool { this.fixedBlockRegionHashMutex.Lock() defer this.fixedBlockRegionHashMutex.Unlock() if country == "" || province == "" { return true } if country != "中国" { return true } if _, ok := this.fixedBlockRegionHash[province]; ok { return true } if _, ok := this.fixedBlockRegionHash[city]; ok { return true } if _, ok := this.fixedBlockRegionHash[province + "/" + city]; ok { return true } return false }