Skip to content

Commit

Permalink
[chore] do know what to do
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Jun 20, 2024
1 parent 8946bbe commit 4cbc079
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 25 deletions.
14 changes: 9 additions & 5 deletions vngcloud/services/loadbalancer/v2/irequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,15 @@ type IDeleteLoadBalancerByIdRequest interface {
type IHealthMonitorRequest interface {
ToRequestBody() interface{}
ToMap() map[string]interface{}
}

type IHealthMonitorTCPRequest interface {
ToRequestBody() interface{}
ToMap() map[string]interface{}
WithHealthyThreshold(pht int) IHealthMonitorRequest
WithUnhealthyThreshold(puht int) IHealthMonitorRequest
WithInterval(pinterval int) IHealthMonitorRequest
WithTimeout(pto int) IHealthMonitorRequest
WithHealthCheckMethod(pmethod HealthCheckMethod) IHealthMonitorRequest
WithHttpVersion(pversion HealthCheckHttpVersion) IHealthMonitorRequest
WithHealthCheckPath(ppath string) IHealthMonitorRequest
WithSuccessCode(pcode string) IHealthMonitorRequest
WithDomainName(pdomain string) IHealthMonitorRequest
}

type IMemberRequest interface {
Expand Down
93 changes: 73 additions & 20 deletions vngcloud/services/loadbalancer/v2/pool_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,14 @@ func NewDeletePoolByIdRequest(plbId, ppoolId string) IDeletePoolByIdRequest {
}

func NewHealthMonitor(pcheckProtocol HealthCheckProtocol) IHealthMonitorRequest {
switch pcheckProtocol {
default:
return newHealthMonitorTCPRequest()
}
opts := new(HealthMonitor)
opts.HealthCheckProtocol = pcheckProtocol
opts.HealthyThreshold = 3
opts.UnhealthyThreshold = 3
opts.Interval = 30
opts.Timeout = 5

return opts
}

func NewMember(pname, pipAddress string, pport int, pmonitorPort int) IMemberRequest {
Expand All @@ -97,21 +101,6 @@ func NewMember(pname, pipAddress string, pport int, pmonitorPort int) IMemberReq
}
}

func newHealthMonitorTCPRequest() IHealthMonitorTCPRequest {
return &HealthMonitor{
HealthCheckProtocol: HealthCheckProtocolTCP,
HealthyThreshold: 3,
UnhealthyThreshold: 3,
Interval: 30,
Timeout: 5,
HealthCheckPath: nil,
HttpVersion: nil,
SuccessCode: nil,
HealthCheckMethod: nil,
DomainName: nil,
}
}

type (
PoolAlgorithm string
PoolProtocol string
Expand Down Expand Up @@ -181,10 +170,11 @@ type UpdatePoolMembersRequest struct {
}

func (s *CreatePoolRequest) ToRequestBody() interface{} {
s.HealthMonitor = s.HealthMonitor.(*HealthMonitor).toRequestBody()
return s
}

func (s *HealthMonitor) validate() {
func (s *HealthMonitor) toRequestBody() IHealthMonitorRequest {
switch s.HealthCheckProtocol {
case HealthCheckProtocolPINGUDP, HealthCheckProtocolTCP:
s.HealthCheckPath = nil
Expand All @@ -208,6 +198,8 @@ func (s *HealthMonitor) validate() {
}
}
}

return s
}

func (s *CreatePoolRequest) WithHealthMonitor(pmonitor IHealthMonitorRequest) ICreatePoolRequest {
Expand Down Expand Up @@ -252,6 +244,67 @@ func (s *HealthMonitor) ToRequestBody() interface{} {
return s
}

func (s *HealthMonitor) WithHealthyThreshold(pht int) IHealthMonitorRequest {
if pht < 1 {
pht = 3
}

s.HealthyThreshold = pht
return s
}

func (s *HealthMonitor) WithUnhealthyThreshold(puht int) IHealthMonitorRequest {
if puht < 1 {
puht = 3
}

s.UnhealthyThreshold = puht
return s
}

func (s *HealthMonitor) WithInterval(pinterval int) IHealthMonitorRequest {
if pinterval < 1 {
pinterval = 30
}

s.Interval = pinterval
return s
}

func (s *HealthMonitor) WithTimeout(pto int) IHealthMonitorRequest {
if pto < 1 {
pto = 5
}

s.Timeout = pto
return s
}

func (s *HealthMonitor) WithHealthCheckMethod(pmethod HealthCheckMethod) IHealthMonitorRequest {
s.HealthCheckMethod = &pmethod
return s
}

func (s *HealthMonitor) WithHttpVersion(pversion HealthCheckHttpVersion) IHealthMonitorRequest {
s.HttpVersion = &pversion
return s
}

func (s *HealthMonitor) WithHealthCheckPath(ppath string) IHealthMonitorRequest {
s.HealthCheckPath = &ppath
return s
}

func (s *HealthMonitor) WithDomainName(pdomain string) IHealthMonitorRequest {
s.DomainName = &pdomain
return s
}

func (s *HealthMonitor) WithSuccessCode(pcode string) IHealthMonitorRequest {
s.SuccessCode = &pcode
return s
}

func (s *HealthMonitor) ToMap() map[string]interface{} {
return map[string]interface{}{
"healthCheckProtocol": s.HealthCheckProtocol,
Expand Down

0 comments on commit 4cbc079

Please sign in to comment.