1 Star 0 Fork 0

powerpaas/machine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
locationClient.go 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
Ben Firshman 提交于 2014-12-04 20:28 . Vendor dependencies with Godep
package locationClient
import (
"bytes"
"encoding/xml"
"errors"
"fmt"
azure "github.com/MSOpenTech/azure-sdk-for-go"
"strings"
)
const (
azureLocationListURL = "locations"
invalidLocationError = "Invalid location: %s. Available locations: %s"
)
func ResolveLocation(location string) error {
if len(location) == 0 {
return fmt.Errorf(azure.ParamNotSpecifiedError, "location")
}
locations, err := GetLocationList()
if err != nil {
return err
}
for _, existingLocation := range locations.Locations {
if existingLocation.Name != location {
continue
}
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(), ", ")))
}
func GetLocationList() (LocationList, error) {
locationList := LocationList{}
response, err := azure.SendAzureGetRequest(azureLocationListURL)
if err != nil {
return locationList, err
}
err = xml.Unmarshal(response, &locationList)
if err != nil {
return locationList, err
}
return locationList, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/powerpaas/machine.git
git@gitee.com:powerpaas/machine.git
powerpaas
machine
machine
v0.1.0-rc1

搜索帮助

Cb406eda 1850385 E526c682 1850385