v1.3.0
This commit is contained in:
@@ -2,38 +2,30 @@ package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create virtual image
|
||||
type CreateVirtualRequest struct {
|
||||
// Name of the virtual image to create
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// ID of real image to link this virtual image to upon creation
|
||||
// Required: true
|
||||
TargetID uint64 `url:"targetId" json:"targetId"`
|
||||
}
|
||||
|
||||
func (irq CreateVirtualRequest) validate() error {
|
||||
if irq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
if irq.TargetID == 0 {
|
||||
return errors.New("validation-error: field TargetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
TargetID uint64 `url:"targetId" json:"targetId" validate:"required"`
|
||||
}
|
||||
|
||||
// CreateVirtual creates virtual image
|
||||
func (i Image) CreateVirtual(ctx context.Context, req CreateVirtualRequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/createVirtual"
|
||||
|
||||
Reference in New Issue
Block a user