Skip to content

Commit

Permalink
Add size unit to LB API. (#477)
Browse files Browse the repository at this point in the history
* Add size unit to LB API.

* Fix spacing in test json.

* Add doc comments to load balancer size fields.
  • Loading branch information
wez470 authored Sep 22, 2021
1 parent 9982a7c commit cd7326c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
23 changes: 15 additions & 8 deletions load_balancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ type LoadBalancersService interface {
// LoadBalancer represents a DigitalOcean load balancer configuration.
// Tags can only be provided upon the creation of a Load Balancer.
type LoadBalancer struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
IP string `json:"ip,omitempty"`
SizeSlug string `json:"size,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
IP string `json:"ip,omitempty"`
// SizeSlug is mutually exclusive with SizeUnit. Only one should be specified
SizeSlug string `json:"size,omitempty"`
// SizeUnit is mutually exclusive with SizeSlug. Only one should be specified
SizeUnit uint32 `json:"size_unit,omitempty"`
Algorithm string `json:"algorithm,omitempty"`
Status string `json:"status,omitempty"`
Created string `json:"created_at,omitempty"`
Expand Down Expand Up @@ -65,6 +68,7 @@ func (l LoadBalancer) AsRequest() *LoadBalancerRequest {
Name: l.Name,
Algorithm: l.Algorithm,
SizeSlug: l.SizeSlug,
SizeUnit: l.SizeUnit,
ForwardingRules: append([]ForwardingRule(nil), l.ForwardingRules...),
DropletIDs: append([]int(nil), l.DropletIDs...),
Tag: l.Tag,
Expand Down Expand Up @@ -134,10 +138,13 @@ func (s StickySessions) String() string {

// LoadBalancerRequest represents the configuration to be applied to an existing or a new load balancer.
type LoadBalancerRequest struct {
Name string `json:"name,omitempty"`
Algorithm string `json:"algorithm,omitempty"`
Region string `json:"region,omitempty"`
SizeSlug string `json:"size,omitempty"`
Name string `json:"name,omitempty"`
Algorithm string `json:"algorithm,omitempty"`
Region string `json:"region,omitempty"`
// SizeSlug is mutually exclusive with SizeUnit. Only one should be specified
SizeSlug string `json:"size,omitempty"`
// SizeUnit is mutually exclusive with SizeSlug. Only one should be specified
SizeUnit uint32 `json:"size_unit,omitempty"`
ForwardingRules []ForwardingRule `json:"forwarding_rules,omitempty"`
HealthCheck *HealthCheck `json:"health_check,omitempty"`
StickySessions *StickySessions `json:"sticky_sessions,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions load_balancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ var lbUpdateJSONResponse = `
"ip":"12.34.56.78",
"algorithm":"least_connections",
"status":"active",
"size_unit":2,
"created_at":"2016-12-15T14:19:09Z",
"forwarding_rules":[
{
Expand Down Expand Up @@ -454,6 +455,7 @@ func TestLoadBalancers_Update(t *testing.T) {
Name: "example-lb-01",
Algorithm: "least_connections",
Region: "nyc1",
SizeUnit: 2,
ForwardingRules: []ForwardingRule{
{
EntryProtocol: "http",
Expand Down Expand Up @@ -512,6 +514,7 @@ func TestLoadBalancers_Update(t *testing.T) {
IP: "12.34.56.78",
Algorithm: "least_connections",
Status: "active",
SizeUnit: 2,
Created: "2016-12-15T14:19:09Z",
ForwardingRules: []ForwardingRule{
{
Expand Down

0 comments on commit cd7326c

Please sign in to comment.