Merge 'dev' into 'main'

This commit is contained in:
stSolo
2022-10-03 16:56:47 +03:00
parent 6271fa6d45
commit 5fd450382c
400 changed files with 14394 additions and 13407 deletions

View File

@@ -1,66 +1,55 @@
package lb
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type BackendCreateRequest struct {
LBID uint64 `url:"lbId"`
BackendName string `url:"backendName"`
Algorithm string `url:"algorithm,omitempty"`
Inter uint64 `url:"inter,omitempty"`
DownInter uint64 `url:"downinter,omitempty"`
Rise uint `url:"rise,omitempty"`
Fall uint `url:"fall,omitempty"`
SlowStart uint64 `url:"slowstart,omitempty"`
MaxConn uint `url:"maxconn,omitempty"`
MaxQueue uint `url:"maxqueue,omitempty"`
Weight uint `url:"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
}
func (l LB) BackendCreate(ctx context.Context, req BackendCreateRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/lb/backendCreate"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := l.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package lb
import (
"context"
"errors"
"net/http"
"strconv"
)
type BackendCreateRequest struct {
LBID uint64 `url:"lbId"`
BackendName string `url:"backendName"`
Algorithm string `url:"algorithm,omitempty"`
Inter uint64 `url:"inter,omitempty"`
DownInter uint64 `url:"downinter,omitempty"`
Rise uint `url:"rise,omitempty"`
Fall uint `url:"fall,omitempty"`
SlowStart uint64 `url:"slowstart,omitempty"`
MaxConn uint `url:"maxconn,omitempty"`
MaxQueue uint `url:"maxqueue,omitempty"`
Weight uint `url:"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
}
func (l LB) BackendCreate(ctx context.Context, req BackendCreateRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/lb/backendCreate"
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}