v1.0.0
This commit is contained in:
@@ -7,28 +7,44 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Request struct for create load balancer
|
||||
type CreateRequest struct {
|
||||
RGID uint64 `url:"rgId"`
|
||||
Name string `url:"name"`
|
||||
ExtNetID uint64 `url:"extnetId"`
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
Start bool `url:"start"`
|
||||
// ID of the resource group where this load balancer instance will be located
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId"`
|
||||
|
||||
// Name of the load balancer.
|
||||
// Must be unique among all load balancers in this Resource Group
|
||||
// Required: true
|
||||
Name string `url:"name"`
|
||||
|
||||
// External network to connect this load balancer to
|
||||
// Required: true
|
||||
ExtNetID uint64 `url:"extnetId"`
|
||||
|
||||
// Internal network (VINS) to connect this load balancer to
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
|
||||
// Start now Load balancer
|
||||
// Required: false
|
||||
Start bool `url:"start"`
|
||||
|
||||
// Text description of this load balancer
|
||||
// Required: false
|
||||
Description string `url:"desc,omitempty"`
|
||||
}
|
||||
|
||||
func (lbrq CreateRequest) Validate() error {
|
||||
func (lbrq CreateRequest) validate() error {
|
||||
if lbrq.RGID == 0 {
|
||||
return errors.New("validation-error: field RGID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if lbrq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
|
||||
if lbrq.ExtNetID == 0 {
|
||||
return errors.New("validation-error: field ExtNetID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if lbrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -36,8 +52,9 @@ func (lbrq CreateRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create method will create a new load balancer instance
|
||||
func (l LB) Create(ctx context.Context, req CreateRequest) (string, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -49,5 +66,7 @@ func (l LB) Create(ctx context.Context, req CreateRequest) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.ReplaceAll(string(res), "\"", ""), nil
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user