v1.3.0
This commit is contained in:
@@ -2,20 +2,21 @@ package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create backend
|
||||
type BackendCreateRequest struct {
|
||||
// ID of the load balancer instance to backendCreate
|
||||
// Required: true
|
||||
LBID uint64 `url:"lbId" json:"lbId"`
|
||||
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||
|
||||
// Must be unique among all backends of this load balancer - name of the new backend to create
|
||||
// Required: true
|
||||
BackendName string `url:"backendName" json:"backendName"`
|
||||
BackendName string `url:"backendName" json:"backendName" validate:"required"`
|
||||
|
||||
// Algorithm
|
||||
// Should be one of:
|
||||
@@ -23,7 +24,7 @@ type BackendCreateRequest struct {
|
||||
// - static-rr
|
||||
// - leastconn
|
||||
// Required: false
|
||||
Algorithm string `url:"algorithm,omitempty" json:"algorithm,omitempty"`
|
||||
Algorithm string `url:"algorithm,omitempty" json:"algorithm,omitempty" validate:"omitempty,lbAlgorithm"`
|
||||
|
||||
// Interval in milliseconds between two consecutive availability
|
||||
// checks of the server that is considered available
|
||||
@@ -66,22 +67,13 @@ type BackendCreateRequest struct {
|
||||
Weight uint64 `url:"weight,omitempty" json:"weight,omitempty"`
|
||||
}
|
||||
|
||||
func (lbrq BackendCreateRequest) validate() error {
|
||||
if lbrq.LBID == 0 {
|
||||
return errors.New("validation-error: field LBID can not be empty or equal to 0")
|
||||
}
|
||||
if lbrq.BackendName == "" {
|
||||
return errors.New("validation-error: field BackendName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// BackendCreate creates new backend on the specified load balancer
|
||||
func (l LB) BackendCreate(ctx context.Context, req BackendCreateRequest) (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 := "/cloudapi/lb/backendCreate"
|
||||
|
||||
Reference in New Issue
Block a user