v1.0.0
This commit is contained in:
17
pkg/image/image.go
Normal file
17
pkg/image/image.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to images
|
||||
type Image struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for images endpoints
|
||||
func New(client interfaces.Caller) *Image {
|
||||
return &Image{
|
||||
client,
|
||||
}
|
||||
}
|
||||
42
pkg/image/list.go
Normal file
42
pkg/image/list.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/internal/validators"
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/image/models"
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/image/requests"
|
||||
)
|
||||
|
||||
// List gets a list of all images.
|
||||
func (i Image) List(ctx context.Context, req requests.ListImageRequest) (*models.ListImage, error) {
|
||||
|
||||
res, err := i.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := models.ListImage{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets a list of all images as an array of bytes
|
||||
func (i Image) ListRaw(ctx context.Context, req requests.ListImageRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := constants.APIv0 + "/image"
|
||||
|
||||
res, err := i.client.ApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
35
pkg/image/models/model_list.go
Normal file
35
pkg/image/models/model_list.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// ListImage represents the response containing image data.
|
||||
type ListImage struct {
|
||||
Total int `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PerPage int `json:"per_page"`
|
||||
IsApproximateTotal bool `json:"is_approximate_total"`
|
||||
Items []ItemImage `json:"items"`
|
||||
HasMore bool `json:"has_more"`
|
||||
RequestID string `json:"request_id"`
|
||||
}
|
||||
|
||||
// ItemImage represents the details of each image item.
|
||||
type ItemImage struct {
|
||||
Active bool `json:"active"`
|
||||
Filename string `json:"filename"`
|
||||
IsTemplateImage bool `json:"is_template_image"`
|
||||
Created time.Time `json:"created"`
|
||||
Md5 string `json:"md5"`
|
||||
Status string `json:"status"`
|
||||
Modified time.Time `json:"modified"`
|
||||
ImageID int `json:"image_id"`
|
||||
Deleted time.Time `json:"deleted"`
|
||||
UUID string `json:"uuid"`
|
||||
Name string `json:"name"`
|
||||
Mark string `json:"mark"`
|
||||
ShareID string `json:"share_id"`
|
||||
Description string `json:"description"`
|
||||
Size int `json:"size"`
|
||||
ImageType string `json:"image_type"`
|
||||
FileSize int `json:"file_size"`
|
||||
}
|
||||
65
pkg/image/requests/request_list.go
Normal file
65
pkg/image/requests/request_list.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package requests
|
||||
|
||||
// ListImageRequest struct to get list of images
|
||||
type ListImageRequest struct {
|
||||
// Name of image
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Size of image
|
||||
// Required: false
|
||||
Size string `url:"size,omitempty" json:"size,omitempty"`
|
||||
|
||||
// Type of image
|
||||
// Required: false
|
||||
ImageType string `url:"image_type,omitempty" json:"image_type,omitempty" validate:"omitempty,image_type"`
|
||||
|
||||
// Status of image
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty" validate:"omitempty,image_status"`
|
||||
|
||||
// ShareID of image
|
||||
// Required: false
|
||||
ShareID string `url:"share_id,omitempty" json:"share_id,omitempty"`
|
||||
|
||||
// Active if True Image is active
|
||||
// Required: false
|
||||
Active interface{} `url:"active,omitempty" json:"active,omitempty" validate:"omitempty,is_bool"`
|
||||
|
||||
// IsTemplateImage If True Image is template
|
||||
// Required: false
|
||||
// Default: False
|
||||
IsTemplateImage bool `url:"is_template_image,omitempty" json:"is_template_image,omitempty"`
|
||||
|
||||
// Mark of image
|
||||
// Required: false
|
||||
Mark string `url:"mark,omitempty" json:"mark,omitempty"`
|
||||
|
||||
// image for filtering by text field
|
||||
// Required: false
|
||||
FilterText string `url:"filter_text,omitempty" json:"filter_text,omitempty"`
|
||||
|
||||
// List columns which will be used by filter_text
|
||||
// Required: false
|
||||
FilterColumns string `url:"filter_columns,omitempty" json:"filter_columns,omitempty"`
|
||||
|
||||
// List of columns for sorting.
|
||||
// Required: false
|
||||
Sort []string `url:"sort,omitempty" json:"sort,omitempty"`
|
||||
|
||||
// Visibility status of the interface (visible, all, deleted).
|
||||
// Required: false
|
||||
Visibility string `url:"visibility,omitempty" json:"visibility,omitempty" validate:"omitempty,visibility"`
|
||||
|
||||
// Filter VM Images that are unavailable now, because share is unavailable
|
||||
// Required: false
|
||||
HideUnavailable interface{} `url:"hide_unavailable,omitempty" json:"hide_unavailable,omitempty" validate:"omitempty,is_bool"`
|
||||
|
||||
// Number of the page to return.
|
||||
// Required: false
|
||||
Page int `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Number of items to return per page.
|
||||
// Required: false
|
||||
Limit int `url:"limit,omitempty" json:"limit,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user