-
Notifications
You must be signed in to change notification settings - Fork 45
/
region.go
82 lines (73 loc) · 2.34 KB
/
region.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package region
import (
"fmt"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/region"
"sort"
"strings"
)
var (
CN_NORTH_4 = region.NewRegion("cn-north-4",
"https://iotda.cn-north-4.myhuaweicloud.com")
CN_SOUTH_4 = region.NewRegion("cn-south-4",
"https://iotda.cn-south-4.myhuaweicloud.com")
CN_SOUTH_1 = region.NewRegion("cn-south-1",
"https://iotda.cn-south-1.myhuaweicloud.com")
CN_EAST_3 = region.NewRegion("cn-east-3",
"https://iotda.cn-east-3.myhuaweicloud.com")
AP_SOUTHEAST_3 = region.NewRegion("ap-southeast-3",
"https://iotda.ap-southeast-3.myhuaweicloud.com")
AP_SOUTHEAST_2 = region.NewRegion("ap-southeast-2",
"https://iotda.ap-southeast-2.myhuaweicloud.com")
AP_SOUTHEAST_1 = region.NewRegion("ap-southeast-1",
"https://iotda.ap-southeast-1.myhuaweicloud.com")
AF_SOUTH_1 = region.NewRegion("af-south-1",
"https://iotda.af-south-1.myhuaweicloud.com")
ME_EAST_1 = region.NewRegion("me-east-1",
"https://iotda.me-east-1.myhuaweicloud.com")
LA_SOUTH_2 = region.NewRegion("la-south-2",
"https://iotda.la-south-2.myhuaweicloud.com")
)
var staticFields = map[string]*region.Region{
"cn-north-4": CN_NORTH_4,
"cn-south-4": CN_SOUTH_4,
"cn-south-1": CN_SOUTH_1,
"cn-east-3": CN_EAST_3,
"ap-southeast-3": AP_SOUTHEAST_3,
"ap-southeast-2": AP_SOUTHEAST_2,
"ap-southeast-1": AP_SOUTHEAST_1,
"af-south-1": AF_SOUTH_1,
"me-east-1": ME_EAST_1,
"la-south-2": LA_SOUTH_2,
}
var provider = region.DefaultProviderChain("IOTDA")
func getRegionIds() []string {
ids := make([]string, 0, len(staticFields))
for key := range staticFields {
ids = append(ids, key)
}
sort.Strings(ids)
return ids
}
func SafeValueOf(regionId string) (region *region.Region, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("%v", r)
}
}()
region = ValueOf(regionId)
return region, err
}
// Deprecated: This function may panic under certain circumstances. Use SafeValueOf instead.
func ValueOf(regionId string) *region.Region {
if regionId == "" {
panic("unexpected empty parameter: regionId")
}
reg := provider.GetRegion(regionId)
if reg != nil {
return reg
}
if _, ok := staticFields[regionId]; ok {
return staticFields[regionId]
}
panic(fmt.Sprintf("region id '%s' is not in the following supported regions of service 'IoTDA': [%s]", regionId, strings.Join(getRegionIds(), ", ")))
}