diff --git a/clients/locationClient/entities.go b/clients/locationClient/entities.go index 03aa7102bd79..52ce5acbb8fd 100644 --- a/clients/locationClient/entities.go +++ b/clients/locationClient/entities.go @@ -1,7 +1,10 @@ package locationClient import ( + "bytes" "encoding/xml" + "fmt" + "strings" ) type LocationList struct { @@ -17,3 +20,13 @@ type Location struct { WebWorkerRoleSizes []string `xml:"ComputeCapabilities>WebWorkerRoleSizes>RoleSize"` VirtualMachineRoleSizes []string `xml:"ComputeCapabilities>VirtualMachinesRoleSizes>RoleSize"` } + +func (locationList LocationList) String() string { + var buf bytes.Buffer + + for _, location := range locationList.Locations { + buf.WriteString(fmt.Sprintf("%s, ", location.Name)) + } + + return strings.Trim(buf.String(), ", ") +} diff --git a/clients/locationClient/locationClient.go b/clients/locationClient/locationClient.go index 12489b6ec84b..3b58bfc09779 100644 --- a/clients/locationClient/locationClient.go +++ b/clients/locationClient/locationClient.go @@ -1,12 +1,10 @@ package locationClient import ( - "bytes" "encoding/xml" "errors" "fmt" azure "github.com/MSOpenTech/azure-sdk-for-go" - "strings" ) const ( @@ -32,12 +30,7 @@ func ResolveLocation(location string) error { return nil } - var availableLocations bytes.Buffer - for _, existingLocation := range locations.Locations { - availableLocations.WriteString(existingLocation.Name + ", ") - } - - return errors.New(fmt.Sprintf(invalidLocationError, location, strings.Trim(availableLocations.String(), ", "))) + return errors.New(fmt.Sprintf(invalidLocationError, location, locations)) } func GetLocationList() (LocationList, error) { @@ -74,10 +67,5 @@ func GetLocation(location string) (*Location, error) { return &existingLocation, nil } - var availableLocations bytes.Buffer - for _, existingLocation := range locations.Locations { - availableLocations.WriteString(existingLocation.Name + ", ") - } - - return nil, errors.New(fmt.Sprintf(invalidLocationError, location, strings.Trim(availableLocations.String(), ", "))) + return nil, errors.New(fmt.Sprintf(invalidLocationError, location, locations)) }