You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.9 KiB
61 lines
1.9 KiB
package comm
|
|
|
|
// 区域代码:与 pb.Region 枚举值一一对应的英文短代码,用于 stats_global_day.region 等可读字段。
|
|
// console 历史分析、analyze 实时写入、运维统计都用同一套代码,保证跨来源一致。
|
|
|
|
// 注册表口径的两档区域码:app_registry.region / app_service_config.region 只用这两个值
|
|
// (后台的区域选择就只有「国内/海外」两项,见 admin app/utils/regions.ts)。
|
|
// 与下面的细分短代码不是一套东西,别混用;换算见 AppRegion()。
|
|
const (
|
|
RegionCodeCN = "cn" // 国内
|
|
RegionCodeOverseas = "hw" // 海外(统计表里不会出现,筛选时展开成除 cn 外的全部码)
|
|
)
|
|
|
|
var regionCodes = map[int32]string{
|
|
0: "", // RegionUnknown
|
|
1: "cn", // 中国
|
|
2: "us", // 美国
|
|
3: "ea", // 东亚
|
|
4: "sea", // 东南亚
|
|
5: "sa", // 南亚
|
|
6: "me", // 中东
|
|
7: "eu", // 欧洲
|
|
8: "ru", // 俄罗斯
|
|
9: "af", // 非洲
|
|
10: "sam", // 南美
|
|
11: "nam", // 北美
|
|
12: "oc", // 大洋洲
|
|
13: "br", // 巴西
|
|
14: "in", // 印度
|
|
}
|
|
|
|
// RegionCodes 返回全部非空区域短代码(无序)。
|
|
// 后台把区域收敛为「国内(cn)/海外(hw)」两档,展开「海外」时要用到全码表。
|
|
func RegionCodes() []string {
|
|
out := make([]string, 0, len(regionCodes))
|
|
for _, c := range regionCodes {
|
|
if c != "" {
|
|
out = append(out, c)
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// RegionCode 把 pb.Region 枚举值(int32)转成英文短代码;未知返回空串。
|
|
func RegionCode(region int32) string {
|
|
if c, ok := regionCodes[region]; ok {
|
|
return c
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// RegionFromCode 把英文短代码转回 pb.Region 枚举值(int32);空串/未知返回 0。
|
|
// 老配置里区域可能写成短代码(cn/us/...),而编排等表按 int32 分层,需要此反向映射。
|
|
func RegionFromCode(code string) int32 {
|
|
for r, c := range regionCodes {
|
|
if c == code && c != "" {
|
|
return r
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|