diff --git a/v3/client.go b/v3/client.go index e48bc0dca..c1134ba2c 100755 --- a/v3/client.go +++ b/v3/client.go @@ -27,6 +27,17 @@ const ( BGSof1 URL = "https://api-bg-sof-1.exoscale.com/v2" ) +// Zone gets the zone name from the URL. +func (u URL) Zone() (string, bool) { + for zone, url := range Zones { + if url == u { + return zone, true + } + } + + return "", false +} + // Zones represents a list of all Exoscale zone. var Zones map[string]URL = map[string]URL{ "ch-gva-2": CHGva2, diff --git a/v3/generator/client/client.tmpl b/v3/generator/client/client.tmpl index b44f84b5a..7dda67974 100644 --- a/v3/generator/client/client.tmpl +++ b/v3/generator/client/client.tmpl @@ -5,6 +5,17 @@ const ( {{ .Enum }} ) +// Zone gets the zone name from the URL. +func (u URL) Zone() (string, bool) { + for zone, url := range Zones { + if url == u { + return zone, true + } + } + + return "", false +} + // Zones represents a list of all Exoscale zone. var Zones map[string]URL = map[string]URL{ {{ .Zones }}