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 link virtual image to another image
|
||||
type LinkRequest struct {
|
||||
// ID of the virtual image
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId" json:"imageId"`
|
||||
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
|
||||
// ID of real image to link this virtual image to
|
||||
// Required: true
|
||||
TargetID uint64 `url:"targetId" json:"targetId"`
|
||||
}
|
||||
|
||||
func (irq LinkRequest) validate() error {
|
||||
if irq.ImageID == 0 {
|
||||
return errors.New("validation-error: field ImageID 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"`
|
||||
}
|
||||
|
||||
// Link links virtual image to another image in the platform
|
||||
func (i Image) Link(ctx context.Context, req LinkRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/link"
|
||||
|
||||
Reference in New Issue
Block a user