142 lines
3.2 KiB
Go
142 lines
3.2 KiB
Go
package main
|
|
|
|
import (
|
|
"f5"
|
|
"mt"
|
|
)
|
|
|
|
const (
|
|
MT_SERVER_INFO = 0
|
|
MT_ALI_KEY = iota
|
|
MT_IP_WHITE_LIST
|
|
MT_IP_BLACK_LIST
|
|
MT_LAUNCH_WHITE_LIST
|
|
MT_LAUNCH_BLACK_LIST
|
|
MT_BLOCK_PROVINCE_CITY
|
|
MT_MAX
|
|
)
|
|
|
|
type MetaMgr struct {
|
|
f5.MetaMgr
|
|
}
|
|
|
|
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 + "ip_whitelist.json",
|
|
Idx: MT_IP_WHITE_LIST,
|
|
RawMeta: (*mt.IpWhiteListMetas)(nil),
|
|
WrapMeta: (*MtwIpWhiteList)(nil)},
|
|
f5.MetaClass{
|
|
FileName: configDir + "ip_blacklist.json",
|
|
Idx: MT_IP_BLACK_LIST,
|
|
RawMeta: (*mt.IpBlackListMetas)(nil),
|
|
WrapMeta: (*MtwIpBlackList)(nil)},
|
|
f5.MetaClass{
|
|
FileName: configDir + "launch_whitelist.json",
|
|
Idx: MT_LAUNCH_WHITE_LIST,
|
|
RawMeta: (*mt.LaunchWhiteListMetas)(nil),
|
|
WrapMeta: (*MtwLaunchWhiteList)(nil)},
|
|
f5.MetaClass{
|
|
FileName: configDir + "launch_blacklist.json",
|
|
Idx: MT_LAUNCH_BLACK_LIST,
|
|
RawMeta: (*mt.LaunchBlackListMetas)(nil),
|
|
WrapMeta: (*MtwLaunchBlackList)(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()
|
|
return this
|
|
}
|
|
|
|
func (this *MetaMgr) UnInit() {
|
|
this.MetaMgr.UnInit()
|
|
}
|
|
|
|
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) GetIpWhiteList() *MtwIpWhiteList {
|
|
v, ok := this.MetaMgr.GetMetaById(MT_IP_WHITE_LIST, 1).(*MtwIpWhiteList)
|
|
if ok {
|
|
return v
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func (this *MetaMgr) GetIpBlackList() *MtwIpBlackList {
|
|
v, ok := this.MetaMgr.GetMetaById(MT_IP_BLACK_LIST, 1).(*MtwIpBlackList)
|
|
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) GetLaunchBlackList() *MtwLaunchBlackList {
|
|
v, ok := this.MetaMgr.GetMetaById(MT_LAUNCH_BLACK_LIST, 1).(*MtwLaunchBlackList)
|
|
if ok {
|
|
return v
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func (this *MetaMgr) GetFixedBlockProvinceCity() *MtwBlockProvinceCity {
|
|
v, ok := this.MetaMgr.GetMetaById(MT_BLOCK_PROVINCE_CITY, 1).(*MtwBlockProvinceCity)
|
|
if ok {
|
|
return v
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|