435c0d9fc8
This PR switches the Nomad repository from using govendor to Go modules for managing dependencies. Aspects of the Nomad workflow remain pretty much the same. The usual Makefile targets should continue to work as they always did. The API submodule simply defers to the parent Nomad version on the repository, keeping the semantics of API versioning that currently exists.
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
|
|
}
|