Skip to content

Commit

Permalink
Merge pull request #29 from jen20/location-concatenation
Browse files Browse the repository at this point in the history
Add method on entities for concatenating locations
  • Loading branch information
ruslangabitov committed Feb 1, 2015
2 parents 3a38485 + 9a65c0c commit acc54a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
13 changes: 13 additions & 0 deletions clients/locationClient/entities.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package locationClient

import (
"bytes"
"encoding/xml"
"fmt"
"strings"
)

type LocationList struct {
Expand All @@ -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(), ", ")
}
16 changes: 2 additions & 14 deletions clients/locationClient/locationClient.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package locationClient

import (
"bytes"
"encoding/xml"
"errors"
"fmt"
azure "github.com/MSOpenTech/azure-sdk-for-go"
"strings"
)

const (
Expand All @@ -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) {
Expand Down Expand Up @@ -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))
}

0 comments on commit acc54a2

Please sign in to comment.