Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method on entities for concatenating locations #29

Merged
merged 2 commits into from
Feb 1, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add method on entities for concatenating locations
This eliminates some repetition in the location client by implementing
Stringer on a LocationList as a comma separated list of the location
names.
  • Loading branch information
jen20 authored and James Nugent committed Jan 31, 2015

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 6ab955f93ad88ff130d5405f44fd4f5288ba57d3
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 {
@@ -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 (
@@ -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.String()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.String() is redundant

}

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.String()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.String() is redundant

}