open-nomad/vendor/github.com/nicolai86/scaleway-sdk/dashboard.go
Seth Hoenig 435c0d9fc8 deps: Switch to Go modules for dependency management
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.
2020-06-02 14:30:36 -05:00

43 lines
1,007 B
Go

package api
import (
"encoding/json"
"net/http"
"net/url"
)
// DashboardResp represents a dashboard received from the API
type DashboardResp struct {
Dashboard Dashboard
}
// Dashboard represents a dashboard
type Dashboard struct {
VolumesCount int `json:"volumes_count"`
RunningServersCount int `json:"running_servers_count"`
ImagesCount int `json:"images_count"`
SnapshotsCount int `json:"snapshots_count"`
ServersCount int `json:"servers_count"`
IPsCount int `json:"ips_count"`
}
// GetDashboard returns the dashboard
func (s *API) GetDashboard() (*Dashboard, error) {
resp, err := s.GetResponsePaginate(s.computeAPI, "dashboard", url.Values{})
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := s.handleHTTPError([]int{http.StatusOK}, resp)
if err != nil {
return nil, err
}
var dashboard DashboardResp
if err = json.Unmarshal(body, &dashboard); err != nil {
return nil, err
}
return &dashboard.Dashboard, nil
}