Files
opentf/vendor/github.com/profitbricks/profitbricks-sdk-go/location.go
Jasmin Gacic b862cd2ccb Terraform provider ProfitBricks - Data Sources (#11520)
* Terraform ProfitBricks Builder

* make fmt

* Merge remote-tracking branch 'upstream/master' into terraform-provider-profitbricks

# Conflicts:
#	command/internal_plugin_list.go

* Addressing PR remarks

* Removed importers

* Added ProfitBricks Data Sources

* Added documentation

* Updated to REST v3:
- nat parameter for Nics
- availabilityZone for Volumes

Minor code clean up

* Minor code clean up

* Fixed typo in volume documentation

* make fmt

* Addressing requested changes

* Added a step in load balancer tests in CheckDestroy where we are making sure that the test doesn't leave dangling resources in ProfitBricks

* Changed expected image name

* Fixed data center test
Code clean up
2017-02-02 13:26:14 +00:00

67 lines
2.0 KiB
Go

package profitbricks
import (
"encoding/json"
"net/http"
)
type Location struct {
Id string `json:"id,omitempty"`
Type_ string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Metadata DatacenterElementMetadata `json:"metadata,omitempty"`
Properties Properties `json:"properties,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"headers,omitempty"`
}
type Locations struct {
Id string `json:"id,omitempty"`
Type_ string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Items []Location `json:"items,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"headers,omitempty"`
}
type Properties struct {
Name string `json:"name,omitempty"`
Features []string `json:"features,omitempty"`
}
// ListLocations returns location collection data
func ListLocations() Locations {
url := mk_url(location_col_path()) + `?depth=` + Depth
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Content-Type", FullHeader)
return toLocations(do(req))
}
// GetLocation returns location data
func GetLocation(locid string) Location {
url := mk_url(location_path(locid)) + `?depth=` + Depth
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Content-Type", FullHeader)
return toLocation(do(req))
}
func toLocation(resp Resp) Location {
var obj Location
json.Unmarshal(resp.Body, &obj)
obj.Response = string(resp.Body)
obj.Headers = &resp.Headers
obj.StatusCode = resp.StatusCode
return obj
}
func toLocations(resp Resp) Locations {
var col Locations
json.Unmarshal(resp.Body, &col)
col.Response = string(resp.Body)
col.Headers = &resp.Headers
col.StatusCode = resp.StatusCode
return col
}