From 1ace995a320f63c460a2efbb5630680f7dee8271 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com> Date: Wed, 17 Jan 2024 10:52:56 +0000 Subject: [PATCH] V3: Get zone name from URL Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com> --- v3/client.go | 11 +++++++++++ v3/generator/client/client.tmpl | 11 +++++++++++ 2 files changed, 22 insertions(+) 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 }}