endpoints.go 890 B

12345678910111213141516171819202122232425262728293031
  1. // Package endpoints validates regional endpoints for services.
  2. package endpoints
  3. //go:generate go run ../model/cli/gen-endpoints/main.go endpoints.json endpoints_map.go
  4. //go:generate gofmt -s -w endpoints_map.go
  5. import "strings"
  6. // EndpointForRegion returns an endpoint and its signing region for a service and region.
  7. // if the service and region pair are not found endpoint and signingRegion will be empty.
  8. func EndpointForRegion(svcName, region string) (endpoint, signingRegion string) {
  9. derivedKeys := []string{
  10. region + "/" + svcName,
  11. region + "/*",
  12. "*/" + svcName,
  13. "*/*",
  14. }
  15. for _, key := range derivedKeys {
  16. if val, ok := endpointsMap.Endpoints[key]; ok {
  17. ep := val.Endpoint
  18. ep = strings.Replace(ep, "{region}", region, -1)
  19. ep = strings.Replace(ep, "{service}", svcName, -1)
  20. endpoint = ep
  21. signingRegion = val.SigningRegion
  22. return
  23. }
  24. }
  25. return
  26. }