open-nomad/vendor/github.com/nicolai86/scaleway-sdk/container.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

71 lines
1.6 KiB
Go

package api
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
)
// ContainerData represents a container data (S3)
type ContainerData struct {
LastModified string `json:"last_modified"`
Name string `json:"name"`
Size string `json:"size"`
}
type getContainerDatas struct {
Container []*ContainerData `json:"container"`
}
// Container represents a container (S3)
type Container struct {
Organization `json:"organization"`
Name string `json:"name"`
Size string `json:"size"`
}
type getContainers struct {
Containers []*Container `json:"containers"`
}
// GetContainers returns a GetContainers
func (s *API) GetContainers() ([]*Container, error) {
resp, err := s.GetResponsePaginate(s.computeAPI, "containers", 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 containers getContainers
if err = json.Unmarshal(body, &containers); err != nil {
return nil, err
}
return containers.Containers, nil
}
// GetContainerDatas returns a GetContainerDatas
func (s *API) GetContainerDatas(container string) ([]*ContainerData, error) {
resp, err := s.GetResponsePaginate(s.computeAPI, fmt.Sprintf("containers/%s", container), 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 datas getContainerDatas
if err = json.Unmarshal(body, &datas); err != nil {
return nil, err
}
return datas.Container, nil
}