You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
decort-golang-sdk/pkg/cloudbroker/image/get.go

47 lines
1021 B

package image
import (
"context"
"encoding/json"
"net/http"
3 years ago
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
2 years ago
// GetRequest struct to get image details
type GetRequest struct {
3 years ago
// ID of image
// Required: true
3 years ago
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
}
2 years ago
// Get gets image details by ID as a RecordImage struct
3 years ago
func (i Image) Get(ctx context.Context, req GetRequest) (*RecordImage, error) {
2 years ago
res, err := i.GetRaw(ctx, req)
if err != nil {
2 years ago
return nil, err
}
3 years ago
info := RecordImage{}
2 years ago
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
2 years ago
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 {
2 years ago
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
2 years ago
url := "/cloudbroker/image/get"
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}