Skip to content

Commit

Permalink
use pointers for optional fields
Browse files Browse the repository at this point in the history
  • Loading branch information
asobrien committed Jan 22, 2020
1 parent 2767792 commit cf93538
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 69 deletions.
96 changes: 48 additions & 48 deletions fastly/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
PoolTypeHash PoolType = "hash"

// PoolTypeClient ins a pool that does client direction.
PoolTypeClient = "client"
PoolTypeClient PoolType = "client"
)

// PoolType is a type of pool.
Expand Down Expand Up @@ -99,29 +99,30 @@ type CreatePoolInput struct {
Service string
Version int

// Name of the pool (required).
// Name is the name of the pool to create (required).
Name string `form:"name"`

Comment string `form:"comment,omitempty"`
Shield string `form:"shield,omitempty"`
RequestCondition string `form:"request_condition,omitempty"`
MaxConnDefault uint `form:"max_conn_default,omitempty"`
ConnectTimeout uint `form:"connect_timeout,omitempty"`
FirstByteTimeout uint `form:"first_byte_timeout,omitempty"`
Quorum uint `form:"quorum,omitempty"`
// Optional fields.
Comment *string `form:"comment,omitempty"`
Shield *string `form:"shield,omitempty"`
RequestCondition *string `form:"request_condition,omitempty"`
MaxConnDefault *uint `form:"max_conn_default,omitempty"`
ConnectTimeout *uint `form:"connect_timeout,omitempty"`
FirstByteTimeout *uint `form:"first_byte_timeout,omitempty"`
Quorum *uint `form:"quorum,omitempty"`
UseTLS *Compatibool `form:"use_tls,omitempty"`
TLSCACert string `form:"tls_ca_cert,omitempty"`
TLSCiphers string `form:"tls_ciphers,omitempty"`
TLSClientKey string `form:"tls_client_key,omitempty"`
TLSClientCert string `form:"tls_client_cert,omitempty"`
TLSSNIHostname string `form:"tls_sni_hostname,omitempty"`
TLSCheckCert bool `form:"tls_check_cert,omitempty"`
TLSCertHostname string `form:"tls_cert_hostname,omitempty"`
MinTLSVersion string `form:"min_tls_version,omitempty"`
MaxTLSVersion string `form:"max_tls_version,omitempty"`
Healthcheck string `form:"healthcheck,omitempty"`
TLSCACert *string `form:"tls_ca_cert,omitempty"`
TLSCiphers *string `form:"tls_ciphers,omitempty"`
TLSClientKey *string `form:"tls_client_key,omitempty"`
TLSClientCert *string `form:"tls_client_cert,omitempty"`
TLSSNIHostname *string `form:"tls_sni_hostname,omitempty"`
TLSCheckCert *bool `form:"tls_check_cert,omitempty"`
TLSCertHostname *string `form:"tls_cert_hostname,omitempty"`
MinTLSVersion *string `form:"min_tls_version,omitempty"`
MaxTLSVersion *string `form:"max_tls_version,omitempty"`
Healthcheck *string `form:"healthcheck,omitempty"`
Type PoolType `form:"type,omitempty"`
OverrideHost string `form:"override_host,omitempty"`
OverrideHost *string `form:"override_host,omitempty"`
}

// CreatePool creates a pool for a particular service and version.
Expand Down Expand Up @@ -193,34 +194,34 @@ func (c *Client) GetPool(i *GetPoolInput) (*Pool, error) {
// UpdatePoolInput is used as input to the UpdatePool function.
type UpdatePoolInput struct {
// Service is the ID of the service. Version is the specific configuration
// version. Both fields are required.
// version. Name is the name of the pool to update. All three fields
// are required.
Service string
Version int

// Name is the name of the pool to update (required).
Name string

NewName string `form:"name,omitempty"`
Comment string `form:"comment,omitempty"`
Shield string `form:"shield,omitempty"`
RequestCondition string `form:"request_condition,omitempty"`
MaxConnDefault uint `form:"max_conn_default,omitempty"`
ConnectTimeout uint `form:"connect_timeout,omitempty"`
FirstByteTimeout uint `form:"first_byte_timeout,omitempty"`
Quorum uint `form:"quorum,omitempty"`
Name string

// Optional fields.
NewName *string `form:"name,omitempty"`
Comment *string `form:"comment,omitempty"`
Shield *string `form:"shield,omitempty"`
RequestCondition *string `form:"request_condition,omitempty"`
MaxConnDefault *uint `form:"max_conn_default,omitempty"`
ConnectTimeout *uint `form:"connect_timeout,omitempty"`
FirstByteTimeout *uint `form:"first_byte_timeout,omitempty"`
Quorum *uint `form:"quorum,omitempty"`
UseTLS *Compatibool `form:"use_tls,omitempty"`
TLSCACert string `form:"tls_ca_cert,omitempty"`
TLSCiphers string `form:"tls_ciphers,omitempty"`
TLSClientKey string `form:"tls_client_key,omitempty"`
TLSClientCert string `form:"tls_client_cert,omitempty"`
TLSSNIHostname string `form:"tls_sni_hostname,omitempty"`
TLSCheckCert bool `form:"tls_check_cert,omitempty"`
TLSCertHostname string `form:"tls_cert_hostname,omitempty"`
MinTLSVersion string `form:"min_tls_version,omitempty"`
MaxTLSVersion string `form:"max_tls_version,omitempty"`
Healthcheck string `form:"healthcheck,omitempty"`
TLSCACert *string `form:"tls_ca_cert,omitempty"`
TLSCiphers *string `form:"tls_ciphers,omitempty"`
TLSClientKey *string `form:"tls_client_key,omitempty"`
TLSClientCert *string `form:"tls_client_cert,omitempty"`
TLSSNIHostname *string `form:"tls_sni_hostname,omitempty"`
TLSCheckCert *bool `form:"tls_check_cert,omitempty"`
TLSCertHostname *string `form:"tls_cert_hostname,omitempty"`
MinTLSVersion *string `form:"min_tls_version,omitempty"`
MaxTLSVersion *string `form:"max_tls_version,omitempty"`
Healthcheck *string `form:"healthcheck,omitempty"`
Type PoolType `form:"type,omitempty"`
OverrideHost string `form:"override_host,omitempty"`
OverrideHost *string `form:"override_host,omitempty"`
}

// UpdatePool updates a specufic pool for a particular service and version.
Expand Down Expand Up @@ -253,12 +254,11 @@ func (c *Client) UpdatePool(i *UpdatePoolInput) (*Pool, error) {
// DeletePoolInput is used as input to the DeletePool function.
type DeletePoolInput struct {
// Service is the ID of the service. Version is the specific configuration
// version. Both fields are required.
// version. Name is the name of the pool to delete. All three fields
// are required.
Service string
Version int

// Name is the name of the pool to delete (required).
Name string
Name string
}

// DeletePool deletes a specific pool for a particular service and version.
Expand Down
12 changes: 6 additions & 6 deletions fastly/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func TestClient_Pools(t *testing.T) {
Service: testServiceID,
Version: tv.Number,
Name: "test_pool",
Comment: "test pool",
Quorum: 50,
Comment: String("test pool"),
Quorum: Uint(50),
UseTLS: CBool(true),
TLSCertHostname: "example.com",
TLSCertHostname: String("example.com"),
Type: PoolTypeRandom,
})
})
Expand Down Expand Up @@ -110,8 +110,8 @@ func TestClient_Pools(t *testing.T) {
Service: testServiceID,
Version: tv.Number,
Name: "test_pool",
NewName: "new_test_pool",
Quorum: 100,
NewName: String("new_test_pool"),
Quorum: Uint(0),
})
})
if err != nil {
Expand All @@ -120,7 +120,7 @@ func TestClient_Pools(t *testing.T) {
if up.Name != "new_test_pool" {
t.Errorf("bad name: %q", up.Name)
}
if up.Quorum != 100 {
if up.Quorum != 0 {
t.Errorf("bad quorum: %q", up.Quorum)
}

Expand Down
28 changes: 15 additions & 13 deletions fastly/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ type CreateServerInput struct {
// Address is the hostname or IP of the origin server (required).
Address string `form:"address"`

Comment string `form:"comment,omitempty"`
Weight uint `form:"weight,omitempty"`
MaxConn uint `form:"max_conn,omitempty"`
Port uint `form:"port,omitempty"`
Disabled bool `form:"disabled,omitempty"`
OverrideHost string `form:"override_host,omitempty"`
// Optional fields.
Comment *string `form:"comment,omitempty"`
Weight *uint `form:"weight,omitempty"`
MaxConn *uint `form:"max_conn,omitempty"`
Port *uint `form:"port,omitempty"`
Disabled *bool `form:"disabled,omitempty"`
OverrideHost *string `form:"override_host,omitempty"`
}

// CreateServer creates a single server for a particular service and pool.
Expand Down Expand Up @@ -157,13 +158,14 @@ type UpdateServerInput struct {
Pool string
Server string

Address string `form:"address,omitempty"`
Comment string `form:"comment,omitempty"`
Weight uint `form:"weight,omitempty"`
MaxConn uint `form:"max_conn,omitempty"`
Port uint `form:"port,omitempty"`
Disabled bool `form:"disabled,omitempty"`
OverrideHost string `form:"override_host,omitempty"`
// Optional fields.
Address *string `form:"address,omitempty"`
Comment *string `form:"comment,omitempty"`
Weight *uint `form:"weight,omitempty"`
MaxConn *uint `form:"max_conn,omitempty"`
Port *uint `form:"port,omitempty"`
Disabled *bool `form:"disabled,omitempty"`
OverrideHost *string `form:"override_host,omitempty"`
}

// UpdateServer updates a single server for a particular service and pool.
Expand Down
4 changes: 2 additions & 2 deletions fastly/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ func TestClient_Servers(t *testing.T) {
Service: testServiceID,
Pool: testPool.ID,
Server: server.ID,
Address: "0.0.0.0",
Weight: 50,
Address: String("0.0.0.0"),
Weight: Uint(50),
})
})
if err != nil {
Expand Down

0 comments on commit cf93538

Please sign in to comment.