Skip to content

Commit

Permalink
* change failover groups routes (#46)
Browse files Browse the repository at this point in the history
* change failover groups function parameters to pointers
  • Loading branch information
jin-cloud66 authored Dec 13, 2021
1 parent dde882d commit 23c7c66
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
36 changes: 24 additions & 12 deletions failover-group.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cloud66

import (
"strings"
"time"
)

Expand Down Expand Up @@ -30,7 +31,7 @@ func (c *Client) FailoverGroupList() ([]FailoverGroup, error) {

var result []FailoverGroup

req, err := c.NewRequest("GET", "/elastic_addresses.json", nil, queryStrings)
req, err := c.NewRequest("GET", "/failover_groups.json", nil, queryStrings)
if err != nil {
return nil, err
}
Expand All @@ -43,36 +44,36 @@ func (c *Client) FailoverGroupList() ([]FailoverGroup, error) {
return result, nil
}

func (c *Client) AddFailoverGroup(primaryStack string, secondaryStack string, currentStack CurrentStackType) error {
func (c *Client) AddFailoverGroup(primaryStack *string, secondaryStack *string, currentStack *CurrentStackType) error {
params := struct {
PrimaryStack string `json:"primary_stack_uid"`
SecondaryStack string `json:"secondary_stack_uid"`
CurrentStack CurrentStackType `json:"current_stack"`
PrimaryStack *string `json:"primary_stack_uid"`
SecondaryStack *string `json:"secondary_stack_uid"`
CurrentStack *CurrentStackType `json:"current_stack"`
}{
PrimaryStack: primaryStack,
SecondaryStack: secondaryStack,
CurrentStack: currentStack,
}

req, err := c.NewRequest("POST", "/elastic_addresses", params, nil)
req, err := c.NewRequest("POST", "/failover_groups", params, nil)
if err != nil {
return err
}
return c.DoReq(req, nil, nil)
}

func (c *Client) UpdateFailoverGroup(failoverGroupUid string, primaryStack string, secondaryStack string, currentStack CurrentStackType) error {
func (c *Client) UpdateFailoverGroup(failoverGroupUid string, primaryStack *string, secondaryStack *string, currentStack *CurrentStackType) error {
params := struct {
PrimaryStack string `json:"primary_stack_uid"`
SecondaryStack string `json:"secondary_stack_uid"`
CurrentStack CurrentStackType `json:"current_stack"`
PrimaryStack *string `json:"primary_stack_uid"`
SecondaryStack *string `json:"secondary_stack_uid"`
CurrentStack *CurrentStackType `json:"current_stack"`
}{
PrimaryStack: primaryStack,
SecondaryStack: secondaryStack,
CurrentStack: currentStack,
}

req, err := c.NewRequest("PUT", "/elastic_addresses/"+failoverGroupUid, params, nil)
req, err := c.NewRequest("PUT", "/failover_groups/"+failoverGroupUid, params, nil)
if err != nil {
return err
}
Expand All @@ -81,7 +82,7 @@ func (c *Client) UpdateFailoverGroup(failoverGroupUid string, primaryStack strin
}

func (c *Client) DeleteFailoverGrouop(failoverGroupUid string) error {
req, err := c.NewRequest("DELETE", "/elastic_addresses/"+failoverGroupUid, nil, nil)
req, err := c.NewRequest("DELETE", "/failover_groups/"+failoverGroupUid, nil, nil)
if err != nil {
return err
}
Expand All @@ -97,3 +98,14 @@ func (currentStackType *CurrentStackType) String() string {
}
return "Wrong CurrentStackType"
}

func ParseCurrentStack(param string) CurrentStackType {
if strings.EqualFold(param, "primary") {
return STACK_PRIMARY
}

if strings.EqualFold(param, "secondary") {
return STACK_SECONDARY
}
return STACK_PRIMARY
}
2 changes: 1 addition & 1 deletion stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (c *Client) StackList() ([]Stack, error) {
return result, nil
}

func (c *Client) StackListWithFilter(filter filterFunction, environment string) ([]Stack, error) {
func (c *Client) StackListWithFilter(filter filterFunction, environment *string) ([]Stack, error) {
queryStrings := make(map[string]string)
queryStrings["page"] = "1"

Expand Down

0 comments on commit 23c7c66

Please sign in to comment.