This commit is contained in:
asteam
2025-09-23 14:34:24 +03:00
parent b924e85e49
commit f1ffb4c0fd
1108 changed files with 72020 additions and 0 deletions

52
pkg/cloudapi/image/get.go Normal file
View File

@@ -0,0 +1,52 @@
package image
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// GetRequest struct to get detailed information about image
type GetRequest struct {
// ID of image to get
// Required: true
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
// If set to False returns only images in status CREATED
// Required: false
ShowAll bool `url:"showAll,omitempty" json:"showAll,omitempty"`
}
// Get gets image by ID.
// Returns image as a RecordImage struct if user has rights on it
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 by ID.
// Returns image as an array of bytes if user has rights on it
func (i Image) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/image/get"
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}