代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。