-
Notifications
You must be signed in to change notification settings - Fork 4
/
aws_region.go
57 lines (48 loc) · 1.58 KB
/
aws_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
package remoteconfig
import "errors"
type AWSRegion string
const (
AWS_REGION_US_EAST_1 AWSRegion = "us-east-1"
AWS_REGION_US_WEST_1 AWSRegion = "us-west-1"
AWS_REGION_US_WEST_2 AWSRegion = "us-west-2"
AWS_REGION_US_GOV_WEST_1 AWSRegion = "us-gov-west-1"
AWS_REGION_EU_WEST_1 AWSRegion = "eu-west-1"
AWS_REGION_EU_CENTRAL_1 AWSRegion = "eu-central-1"
AWS_REGION_AP_SOUTHEAST_1 AWSRegion = "ap-southeast-1"
AWS_REGION_AP_SOUTHEAST_2 AWSRegion = "ap-southeast-2"
AWS_REGION_AP_NORTHEAST_1 AWSRegion = "ap-northeast-1"
AWS_REGION_SA_EAST_1 AWSRegion = "sa-east-1"
)
var AWSRegions = []AWSRegion{
AWS_REGION_US_EAST_1,
AWS_REGION_US_WEST_1,
AWS_REGION_US_WEST_2,
AWS_REGION_US_GOV_WEST_1,
AWS_REGION_EU_WEST_1,
AWS_REGION_EU_CENTRAL_1,
AWS_REGION_AP_SOUTHEAST_1,
AWS_REGION_AP_SOUTHEAST_2,
AWS_REGION_AP_NORTHEAST_1,
AWS_REGION_SA_EAST_1,
}
var (
ErrAWSRegionEmptyString = errors.New("Region cannot be empty")
ErrAWSRegionInvalid = errors.New("Region is invalid")
)
func (r *AWSRegion) UnmarshalText(data []byte) error {
rString := string(data[:])
*r = (AWSRegion)(rString)
return r.Validate()
}
func (r AWSRegion) Validate() error {
if r == "" {
return ErrAWSRegionEmptyString
}
if r != AWS_REGION_US_EAST_1 && r != AWS_REGION_US_WEST_1 && r != AWS_REGION_US_WEST_2 && r != AWS_REGION_US_GOV_WEST_1 &&
r != AWS_REGION_EU_WEST_1 && r != AWS_REGION_EU_CENTRAL_1 &&
r != AWS_REGION_AP_SOUTHEAST_1 && r != AWS_REGION_AP_SOUTHEAST_2 && r != AWS_REGION_AP_NORTHEAST_1 &&
r != AWS_REGION_SA_EAST_1 {
return ErrAWSRegionInvalid
}
return nil
}