diff --git a/endpoints/endpoints_gen.go b/endpoints/endpoints_gen.go index 891e5634..ceb98e58 100644 --- a/endpoints/endpoints_gen.go +++ b/endpoints/endpoints_gen.go @@ -69,20 +69,13 @@ const ( UsGovWest1RegionID = "us-gov-west-1" // AWS GovCloud (US-West) ) -type partitionAndRegions struct { - partition Partition - regions map[string]Region -} - var ( - partitionsAndRegions = map[string]partitionAndRegions{ + partitions = map[string]Partition{ AwsPartitionID: { - partition: Partition{ - id: AwsPartitionID, - name: "AWS Standard", - dnsSuffix: "amazonaws.com", - regionRegex: regexp.MustCompile(`^(us|eu|ap|sa|ca|me|af|il|mx)\-\w+\-\d+$`), - }, + id: AwsPartitionID, + name: "AWS Standard", + dnsSuffix: "amazonaws.com", + regionRegex: regexp.MustCompile(`^(us|eu|ap|sa|ca|me|af|il|mx)\-\w+\-\d+$`), regions: map[string]Region{ AfSouth1RegionID: { id: AfSouth1RegionID, @@ -207,12 +200,10 @@ var ( }, }, AwsCnPartitionID: { - partition: Partition{ - id: AwsCnPartitionID, - name: "AWS China", - dnsSuffix: "amazonaws.com.cn", - regionRegex: regexp.MustCompile(`^cn\-\w+\-\d+$`), - }, + id: AwsCnPartitionID, + name: "AWS China", + dnsSuffix: "amazonaws.com.cn", + regionRegex: regexp.MustCompile(`^cn\-\w+\-\d+$`), regions: map[string]Region{ CnNorth1RegionID: { id: CnNorth1RegionID, @@ -225,12 +216,10 @@ var ( }, }, AwsIsoPartitionID: { - partition: Partition{ - id: AwsIsoPartitionID, - name: "AWS ISO (US)", - dnsSuffix: "c2s.ic.gov", - regionRegex: regexp.MustCompile(`^us\-iso\-\w+\-\d+$`), - }, + id: AwsIsoPartitionID, + name: "AWS ISO (US)", + dnsSuffix: "c2s.ic.gov", + regionRegex: regexp.MustCompile(`^us\-iso\-\w+\-\d+$`), regions: map[string]Region{ UsIsoEast1RegionID: { id: UsIsoEast1RegionID, @@ -243,12 +232,10 @@ var ( }, }, AwsIsoBPartitionID: { - partition: Partition{ - id: AwsIsoBPartitionID, - name: "AWS ISOB (US)", - dnsSuffix: "sc2s.sgov.gov", - regionRegex: regexp.MustCompile(`^us\-isob\-\w+\-\d+$`), - }, + id: AwsIsoBPartitionID, + name: "AWS ISOB (US)", + dnsSuffix: "sc2s.sgov.gov", + regionRegex: regexp.MustCompile(`^us\-isob\-\w+\-\d+$`), regions: map[string]Region{ UsIsobEast1RegionID: { id: UsIsobEast1RegionID, @@ -257,12 +244,10 @@ var ( }, }, AwsIsoEPartitionID: { - partition: Partition{ - id: AwsIsoEPartitionID, - name: "AWS ISOE (Europe)", - dnsSuffix: "cloud.adc-e.uk", - regionRegex: regexp.MustCompile(`^eu\-isoe\-\w+\-\d+$`), - }, + id: AwsIsoEPartitionID, + name: "AWS ISOE (Europe)", + dnsSuffix: "cloud.adc-e.uk", + regionRegex: regexp.MustCompile(`^eu\-isoe\-\w+\-\d+$`), regions: map[string]Region{ EuIsoeWest1RegionID: { id: EuIsoeWest1RegionID, @@ -271,21 +256,17 @@ var ( }, }, AwsIsoFPartitionID: { - partition: Partition{ - id: AwsIsoFPartitionID, - name: "AWS ISOF", - dnsSuffix: "csp.hci.ic.gov", - regionRegex: regexp.MustCompile(`^us\-isof\-\w+\-\d+$`), - }, - regions: map[string]Region{}, + id: AwsIsoFPartitionID, + name: "AWS ISOF", + dnsSuffix: "csp.hci.ic.gov", + regionRegex: regexp.MustCompile(`^us\-isof\-\w+\-\d+$`), + regions: map[string]Region{}, }, AwsUsGovPartitionID: { - partition: Partition{ - id: AwsUsGovPartitionID, - name: "AWS GovCloud (US)", - dnsSuffix: "amazonaws.com", - regionRegex: regexp.MustCompile(`^us\-gov\-\w+\-\d+$`), - }, + id: AwsUsGovPartitionID, + name: "AWS GovCloud (US)", + dnsSuffix: "amazonaws.com", + regionRegex: regexp.MustCompile(`^us\-gov\-\w+\-\d+$`), regions: map[string]Region{ UsGovEast1RegionID: { id: UsGovEast1RegionID, diff --git a/endpoints/partition.go b/endpoints/partition.go index 44423776..ddc20a01 100644 --- a/endpoints/partition.go +++ b/endpoints/partition.go @@ -15,6 +15,7 @@ type Partition struct { name string dnsSuffix string regionRegex *regexp.Regexp + regions map[string]Region } // ID returns the identifier of the partition. @@ -39,20 +40,15 @@ func (p Partition) RegionRegex() *regexp.Regexp { // Regions returns a map of Regions for the partition, indexed by their ID. func (p Partition) Regions() map[string]Region { - partitionAndRegion, ok := partitionsAndRegions[p.id] - if !ok { - return nil - } - - return maps.Clone(partitionAndRegion.regions) + return maps.Clone(p.regions) } // DefaultPartitions returns a list of the partitions. func DefaultPartitions() []Partition { - ps := make([]Partition, len(partitionsAndRegions)) + ps := make([]Partition, 0, len(partitions)) - for _, v := range partitionsAndRegions { - ps = append(ps, v.partition) + for _, p := range partitions { + ps = append(ps, p) } return ps @@ -61,12 +57,7 @@ func DefaultPartitions() []Partition { // PartitionForRegion returns the first partition which includes the specific Region. func PartitionForRegion(ps []Partition, regionID string) (Partition, bool) { for _, p := range ps { - partitionAndRegion, ok := partitionsAndRegions[p.id] - if !ok { - continue - } - - if _, ok := partitionAndRegion.regions[regionID]; ok || partitionAndRegion.partition.regionRegex.MatchString(regionID) { + if _, ok := p.regions[regionID]; ok || p.regionRegex.MatchString(regionID) { return p, true } } diff --git a/internal/generate/endpoints/output.go.gtpl b/internal/generate/endpoints/output.go.gtpl index 127351c1..481e71fb 100644 --- a/internal/generate/endpoints/output.go.gtpl +++ b/internal/generate/endpoints/output.go.gtpl @@ -26,21 +26,14 @@ const ( {{- end }} ) -type partitionAndRegions struct { - partition Partition - regions map[string]Region -} - var ( - partitionsAndRegions = map[string]partitionAndRegions{ + partitions = map[string]Partition{ {{- range .Partitions }} {{ .ID | KebabToTitle}}PartitionID: { - partition: Partition{ - id: {{ .ID | KebabToTitle}}PartitionID, - name: "{{ .Name }}", - dnsSuffix: "{{ .DNSSuffix }}", - regionRegex: regexp.MustCompile(`{{ .RegionRegex }}`), - }, + id: {{ .ID | KebabToTitle}}PartitionID, + name: "{{ .Name }}", + dnsSuffix: "{{ .DNSSuffix }}", + regionRegex: regexp.MustCompile(`{{ .RegionRegex }}`), regions: map[string]Region{ {{- range .Regions }} {{ .ID | KebabToTitle}}RegionID: {