a5ebab63e7
* New Providers added and updated vendoring for go-discover * Vendor.json formatted using make vendorfmt * Docs/Agent/auto-join: Added documentation for the new providers introduced in this PR * Updated the golang.org/x/sys/unix in the vendor directory * Agent: TestGoDiscoverRegistration updated to reflect the addition of new providers * Deleted terraform.tfstate from vendor. * Deleted terraform.tfstate.backup Deleted terraform state file artifacts from unknown runs. * Updated x/sys/windows vendor for Windows binary compilation
40 lines
975 B
Go
40 lines
975 B
Go
package packngo
|
|
|
|
const spotMarketBasePath = "/market/spot/prices"
|
|
|
|
// SpotMarketService expooses Spot Market methods
|
|
type SpotMarketService interface {
|
|
Prices() (PriceMap, *Response, error)
|
|
}
|
|
|
|
// SpotMarketServiceOp implements SpotMarketService
|
|
type SpotMarketServiceOp struct {
|
|
client *Client
|
|
}
|
|
|
|
// PriceMap is a map of [facility][plan]-> float Price
|
|
type PriceMap map[string]map[string]float64
|
|
|
|
// Prices gets current PriceMap from the API
|
|
func (s *SpotMarketServiceOp) Prices() (PriceMap, *Response, error) {
|
|
root := new(struct {
|
|
SMPs map[string]map[string]struct {
|
|
Price float64 `json:"price"`
|
|
} `json:"spot_market_prices"`
|
|
})
|
|
|
|
resp, err := s.client.DoRequest("GET", spotMarketBasePath, nil, root)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
prices := make(PriceMap)
|
|
for facility, planMap := range root.SMPs {
|
|
prices[facility] = map[string]float64{}
|
|
for plan, v := range planMap {
|
|
prices[facility][plan] = v.Price
|
|
}
|
|
}
|
|
return prices, resp, err
|
|
}
|