Skip to content

Commit

Permalink
[chore] enhance the error category of the loadbalancer api group
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Oct 24, 2024
1 parent 3ec9945 commit 4e6f9c9
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 40 deletions.
1 change: 1 addition & 0 deletions vngcloud/services/loadbalancer/inter/irequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type ICreateLoadBalancerRequest interface {
WithTags(ptags ...string) ICreateLoadBalancerRequest
GetMapHeaders() map[string]string
ParseUserAgent() string
ToMap() map[string]interface{}
}

type ICreateListenerRequest interface {
Expand Down
4 changes: 3 additions & 1 deletion vngcloud/services/loadbalancer/inter/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ func (s *LoadBalancerServiceInternal) CreateLoadBalancer(popts ICreateLoadBalanc

if _, sdkErr := s.VLBClient.Post(url, req); sdkErr != nil {
return nil, lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorLoadBalancerExceedQuota(errResp))
lserr.WithErrorLoadBalancerExceedQuota(errResp)).
WithParameters(popts.ToMap()).
AppendCategories(lserr.ErrCatProductVlb)
}

return resp.ToEntityLoadBalancer(), nil
Expand Down
25 changes: 13 additions & 12 deletions vngcloud/services/loadbalancer/inter/loadbalancer_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ type (
LoadBalancerType string
)

func NewCreateLoadBalancerRequest(puserId, pname, ppackageId, pbeSubnetId, psubnetId string) ICreateLoadBalancerRequest {
opt := new(CreateLoadBalancerRequest)
opt.SetPortalUserId(puserId)
opt.Name = pname
opt.PackageID = ppackageId
opt.Scheme = InterVpcLoadBalancerScheme
opt.BackEndSubnetId = pbeSubnetId
opt.SubnetID = psubnetId
opt.Type = CreateOptsTypeOptLayer4
return opt
}

type CreateLoadBalancerRequest struct {
Name string `json:"name"`
PackageID string `json:"packageId"`
Expand All @@ -46,6 +34,19 @@ type CreateLoadBalancerRequest struct {
lscommon.UserAgent
}

func (s *CreateLoadBalancerRequest) ToMap() map[string]interface{} {
return map[string]interface{}{
"name": s.Name,
"packageId": s.PackageID,
"scheme": s.Scheme,
"subnetId": s.SubnetID,
"backendSubnetId": s.BackEndSubnetId,
"projectId": s.ProjectId,
"type": s.Type,
"tags": s.Tags,
}
}

func (s *CreateLoadBalancerRequest) ToRequestBody() interface{} {
if s.Pool != nil {
s.Pool = s.Pool.ToRequestBody().(*CreatePoolRequest)
Expand Down
13 changes: 13 additions & 0 deletions vngcloud/services/loadbalancer/inter/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package inter

func NewCreateLoadBalancerRequest(puserId, pname, ppackageId, pbeSubnetId, psubnetId string) ICreateLoadBalancerRequest {
opt := new(CreateLoadBalancerRequest)
opt.SetPortalUserId(puserId)
opt.Name = pname
opt.PackageID = ppackageId
opt.Scheme = InterVpcLoadBalancerScheme
opt.BackEndSubnetId = pbeSubnetId
opt.SubnetID = psubnetId
opt.Type = CreateOptsTypeOptLayer4
return opt
}
1 change: 1 addition & 0 deletions vngcloud/services/loadbalancer/v2/irequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type ICreateLoadBalancerRequest interface {
WithSubnetId(psubnetId string) ICreateLoadBalancerRequest
WithType(ptype LoadBalancerType) ICreateLoadBalancerRequest
ParseUserAgent() string
ToMap() map[string]interface{}
}

type IGetLoadBalancerByIdRequest interface {
Expand Down
1 change: 1 addition & 0 deletions vngcloud/services/loadbalancer/v2/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func (s *LoadBalancerServiceV2) CreateLoadBalancer(popts ICreateLoadBalancerRequ
if _, sdkErr := s.VLBClient.Post(url, req); sdkErr != nil {
return nil, lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorLoadBalancerExceedQuota(errResp)).
WithParameters(popts.ToMap()).
AppendCategories(lserr.ErrCatProductVlb)
}

Expand Down
41 changes: 14 additions & 27 deletions vngcloud/services/loadbalancer/v2/loadbalancer_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,6 @@ type (
LoadBalancerType string
)

func NewCreateLoadBalancerRequest(pname string) ICreateLoadBalancerRequest {
return &CreateLoadBalancerRequest{
Name: pname,
Scheme: InternetLoadBalancerScheme,
Type: LoadBalancerTypeLayer4,
}
}

func NewGetLoadBalancerByIdRequest(plbId string) IGetLoadBalancerByIdRequest {
opts := new(GetLoadBalancerByIdRequest)
opts.LoadBalancerId = plbId
return opts
}

func NewListLoadBalancersRequest(ppage, psize int) IListLoadBalancersRequest {
opts := new(ListLoadBalancersRequest)
opts.Page = ppage
opts.Size = psize
return opts
}

func NewDeleteLoadBalancerByIdRequest(plbId string) IDeleteLoadBalancerByIdRequest {
opts := new(DeleteLoadBalancerByIdRequest)
opts.LoadBalancerId = plbId
return opts
}

type CreateLoadBalancerRequest struct {
Name string `json:"name"`
PackageID string `json:"packageId"`
Expand Down Expand Up @@ -83,6 +56,20 @@ type DeleteLoadBalancerByIdRequest struct {
lscommon.LoadBalancerCommon
}

func (S *CreateLoadBalancerRequest) ToMap() map[string]interface{} {
return map[string]interface{}{
"name": S.Name,
"packageId": S.PackageID,
"scheme": S.Scheme,
"autoScalable": S.AutoScalable,
"subnetId": S.SubnetID,
"type": S.Type,
"listener": S.Listener.ToMap(),
"pool": S.Pool.ToMap(),
"tags": S.Tags,
}
}

func (s *CreateLoadBalancerRequest) ToRequestBody() interface{} {
if s.Pool != nil {
s.Pool = s.Pool.ToRequestBody().(*CreatePoolRequest)
Expand Down
28 changes: 28 additions & 0 deletions vngcloud/services/loadbalancer/v2/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package v2

func NewCreateLoadBalancerRequest(pname string) ICreateLoadBalancerRequest {
return &CreateLoadBalancerRequest{
Name: pname,
Scheme: InternetLoadBalancerScheme,
Type: LoadBalancerTypeLayer4,
}
}

func NewGetLoadBalancerByIdRequest(plbId string) IGetLoadBalancerByIdRequest {
opts := new(GetLoadBalancerByIdRequest)
opts.LoadBalancerId = plbId
return opts
}

func NewListLoadBalancersRequest(ppage, psize int) IListLoadBalancersRequest {
opts := new(ListLoadBalancersRequest)
opts.Page = ppage
opts.Size = psize
return opts
}

func NewDeleteLoadBalancerByIdRequest(plbId string) IDeleteLoadBalancerByIdRequest {
opts := new(DeleteLoadBalancerByIdRequest)
opts.LoadBalancerId = plbId
return opts
}

0 comments on commit 4e6f9c9

Please sign in to comment.