v1.6.6
This commit is contained in:
@@ -8,15 +8,32 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get image details
|
||||
// GetRequest struct to get image details
|
||||
type GetRequest struct {
|
||||
// ID of image
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
}
|
||||
|
||||
// Get get image details by ID
|
||||
// Get gets image details by ID as a RecordImage struct
|
||||
func (i Image) Get(ctx context.Context, req GetRequest) (*RecordImage, error) {
|
||||
res, err := i.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordImage{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets image details by ID as an array of bytes
|
||||
func (i Image) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
@@ -26,17 +43,6 @@ func (i Image) Get(ctx context.Context, req GetRequest) (*RecordImage, error) {
|
||||
|
||||
url := "/cloudbroker/image/get"
|
||||
|
||||
info := RecordImage{}
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list available images
|
||||
// ListRequest struct to get list of available images
|
||||
type ListRequest struct {
|
||||
// Filter images by storage endpoint provider ID
|
||||
// Required: false
|
||||
@@ -65,11 +65,9 @@ type ListRequest struct {
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list of information about images
|
||||
// List gets list of information about images as a ListImages struct
|
||||
func (i Image) List(ctx context.Context, req ListRequest) (*ListImages, error) {
|
||||
url := "/cloudbroker/image/list"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
res, err := i.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -83,3 +81,11 @@ func (i Image) List(ctx context.Context, req ListRequest) (*ListImages, error) {
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets list of information about images as an array of bytes
|
||||
func (i Image) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
url := "/cloudbroker/image/list"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user