Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort struct fields #376

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 17 additions & 28 deletions fastly/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import (
)

type ACL struct {
ServiceID string `mapstructure:"service_id"`
ServiceVersion int `mapstructure:"version"`

Name string `mapstructure:"name"`
ID string `mapstructure:"id"`
CreatedAt *time.Time `mapstructure:"created_at"`
UpdatedAt *time.Time `mapstructure:"updated_at"`
DeletedAt *time.Time `mapstructure:"deleted_at"`
CreatedAt *time.Time `mapstructure:"created_at"`
DeletedAt *time.Time `mapstructure:"deleted_at"`
ID string `mapstructure:"id"`
Name string `mapstructure:"name"`
ServiceID string `mapstructure:"service_id"`
ServiceVersion int `mapstructure:"version"`
UpdatedAt *time.Time `mapstructure:"updated_at"`
}

// ACLsByName is a sortable list of ACLs.
Expand All @@ -32,7 +31,6 @@ func (s ACLsByName) Less(i, j int) bool {
type ListACLsInput struct {
// ServiceID is the ID of the service (required).
ServiceID string

// ServiceVersion is the specific configuration version (required).
ServiceVersion int
}
Expand Down Expand Up @@ -64,14 +62,12 @@ func (c *Client) ListACLs(i *ListACLsInput) ([]*ACL, error) {

// CreateACLInput is used as input to the CreateACL function.
type CreateACLInput struct {
// Name is the name of the ACL to create (required)
Name string `url:"name"`
// ServiceID is the ID of the service (required).
ServiceID string

// ServiceVersion is the specific configuration version (required).
ServiceVersion int

// Name is the name of the ACL to create (required)
Name string `url:"name"`
}

func (c *Client) CreateACL(i *CreateACLInput) (*ACL, error) {
Expand Down Expand Up @@ -99,14 +95,12 @@ func (c *Client) CreateACL(i *CreateACLInput) (*ACL, error) {

// DeleteACLInput is the input parameter to DeleteACL function.
type DeleteACLInput struct {
// Name is the name of the ACL to delete (required).
Name string
// ServiceID is the ID of the service (required).
ServiceID string

// ServiceVersion is the specific configuration version (required).
ServiceVersion int

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

// DeleteACL deletes the given ACL version.
Expand Down Expand Up @@ -142,14 +136,12 @@ func (c *Client) DeleteACL(i *DeleteACLInput) error {

// GetACLInput is the input parameter to GetACL function.
type GetACLInput struct {
// Name is the name of the ACL to get (required).
Name string
// ServiceID is the ID of the service (required).
ServiceID string

// ServiceVersion is the specific configuration version (required).
ServiceVersion int

// Name is the name of the ACL to get (required).
Name string
}

// GetACL gets the ACL configuration with the given parameters.
Expand Down Expand Up @@ -182,17 +174,14 @@ func (c *Client) GetACL(i *GetACLInput) (*ACL, error) {

// UpdateACLInput is the input parameter to UpdateACL function.
type UpdateACLInput struct {
// ServiceID is the ID of the service (required).
ServiceID string

// ServiceVersion is the specific configuration version (required).
ServiceVersion int

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

// NewName is the new name of the ACL to update (required).
NewName string `url:"name"`
// ServiceID is the ID of the service (required).
ServiceID string
// ServiceVersion is the specific configuration version (required).
ServiceVersion int
}

// UpdateACL updates the name of the ACL with the given parameters.
Expand Down
68 changes: 31 additions & 37 deletions fastly/acl_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ import (
)

type ACLEntry struct {
ServiceID string `mapstructure:"service_id"`
ACLID string `mapstructure:"acl_id"`

ACLID string `mapstructure:"acl_id"`
Comment string `mapstructure:"comment"`
CreatedAt *time.Time `mapstructure:"created_at"`
DeletedAt *time.Time `mapstructure:"deleted_at"`
ID string `mapstructure:"id"`
IP string `mapstructure:"ip"`
Subnet *int `mapstructure:"subnet"`
Negated bool `mapstructure:"negated"`
Comment string `mapstructure:"comment"`
CreatedAt *time.Time `mapstructure:"created_at"`
ServiceID string `mapstructure:"service_id"`
Subnet *int `mapstructure:"subnet"`
UpdatedAt *time.Time `mapstructure:"updated_at"`
DeletedAt *time.Time `mapstructure:"deleted_at"`
}

// entriesById is a sortable list of ACL entries.
Expand All @@ -36,11 +35,11 @@ func (s entriesById) Less(i, j int) bool {

// ListACLEntriesInput is the input parameter to ListACLEntries function.
type ListACLEntriesInput struct {
ServiceID string
ACLID string
Direction string
PerPage int
Page int
PerPage int
ServiceID string
Sort string
}

Expand Down Expand Up @@ -73,12 +72,14 @@ func (c *Client) ListACLEntries(i *ListACLEntriesInput) ([]*ACLEntry, error) {
}

type ListAclEntriesPaginator struct {
consumed bool
CurrentPage int
NextPage int
LastPage int
client *Client
options *ListACLEntriesInput
NextPage int

// Private
client *Client
consumed bool
options *ListACLEntriesInput
}

// HasNext returns a boolean indicating whether more pages are available
Expand Down Expand Up @@ -187,9 +188,9 @@ func (c *Client) listACLEntriesWithPage(i *ListACLEntriesInput, p *ListAclEntrie

// GetACLEntryInput is the input parameter to GetACLEntry function.
type GetACLEntryInput struct {
ServiceID string
ACLID string
ID string
ServiceID string
}

// GetACLEntry returns a single ACL entry based on its ID.
Expand Down Expand Up @@ -224,15 +225,12 @@ func (c *Client) GetACLEntry(i *GetACLEntryInput) (*ACLEntry, error) {

// CreateACLEntryInput the input parameter to CreateACLEntry function.
type CreateACLEntryInput struct {
// Required fields
ServiceID string
ACLID string
IP string `url:"ip"`

// Optional fields
Subnet int `url:"subnet,omitempty"`
Negated Compatibool `url:"negated,omitempty"`
Comment string `url:"comment,omitempty"`
ServiceID string
Comment string `url:"comment,omitempty"`
Negated Compatibool `url:"negated,omitempty"`
Subnet int `url:"subnet,omitempty"`
}

// CreateACLEntry creates and returns a new ACL entry.
Expand Down Expand Up @@ -267,9 +265,9 @@ func (c *Client) CreateACLEntry(i *CreateACLEntryInput) (*ACLEntry, error) {

// DeleteACLEntryInput the input parameter to DeleteACLEntry function.
type DeleteACLEntryInput struct {
ServiceID string
ACLID string
ID string
ServiceID string
}

// DeleteACLEntry deletes an entry from an ACL based on its ID
Expand Down Expand Up @@ -308,16 +306,13 @@ func (c *Client) DeleteACLEntry(i *DeleteACLEntryInput) error {

// UpdateACLEntryInput is the input parameter to UpdateACLEntry function.
type UpdateACLEntryInput struct {
// Required fields
ServiceID string
ACLID string
Comment *string `url:"comment,omitempty"`
ID string

// Optional fields
IP *string `url:"ip,omitempty"`
Subnet *int `url:"subnet,omitempty"`
Negated *Compatibool `url:"negated,omitempty"`
Comment *string `url:"comment,omitempty"`
IP *string `url:"ip,omitempty"`
Negated *Compatibool `url:"negated,omitempty"`
ServiceID string
Subnet *int `url:"subnet,omitempty"`
}

// UpdateACLEntry updates an ACL entry
Expand Down Expand Up @@ -351,19 +346,18 @@ func (c *Client) UpdateACLEntry(i *UpdateACLEntryInput) (*ACLEntry, error) {
}

type BatchModifyACLEntriesInput struct {
ServiceID string `json:"-"`
ACLID string `json:"-"`

Entries []*BatchACLEntry `json:"entries"`
ACLID string `json:"-"`
Entries []*BatchACLEntry `json:"entries"`
ServiceID string `json:"-"`
}

type BatchACLEntry struct {
Operation BatchOperation `json:"op"`
Comment *string `json:"comment,omitempty"`
ID *string `json:"id,omitempty"`
IP *string `json:"ip,omitempty"`
Subnet *int `json:"subnet,omitempty"`
Negated *Compatibool `json:"negated,omitempty"`
Comment *string `json:"comment,omitempty"`
Operation BatchOperation `json:"op"`
Subnet *int `json:"subnet,omitempty"`
}

func (c *Client) BatchModifyACLEntries(i *BatchModifyACLEntriesInput) error {
Expand Down
77 changes: 33 additions & 44 deletions fastly/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import (

// Backend represents a backend response from the Fastly API.
type Backend struct {
ServiceID string `mapstructure:"service_id"`
ServiceVersion int `mapstructure:"version"`

Address string `mapstructure:"address"`
AutoLoadbalance bool `mapstructure:"auto_loadbalance"`
BetweenBytesTimeout uint `mapstructure:"between_bytes_timeout"`
Expand All @@ -38,6 +35,8 @@ type Backend struct {
SSLClientKey string `mapstructure:"ssl_client_key"`
SSLHostname string `mapstructure:"ssl_hostname"`
SSLSNIHostname string `mapstructure:"ssl_sni_hostname"`
ServiceID string `mapstructure:"service_id"`
ServiceVersion int `mapstructure:"version"`
Shield string `mapstructure:"shield"`
UpdatedAt *time.Time `mapstructure:"updated_at"`
UseSSL bool `mapstructure:"use_ssl"`
Expand All @@ -58,7 +57,6 @@ func (s backendsByName) Less(i, j int) bool {
type ListBackendsInput struct {
// ServiceID is the ID of the service (required).
ServiceID string

// ServiceVersion is the specific configuration version (required).
ServiceVersion int
}
Expand Down Expand Up @@ -90,12 +88,6 @@ func (c *Client) ListBackends(i *ListBackendsInput) ([]*Backend, error) {

// CreateBackendInput is used as input to the CreateBackend function.
type CreateBackendInput struct {
// ServiceID is the ID of the service (required).
ServiceID string

// ServiceVersion is the specific configuration version (required).
ServiceVersion int

Address string `url:"address,omitempty"`
AutoLoadbalance Compatibool `url:"auto_loadbalance,omitempty"`
BetweenBytesTimeout *uint `url:"between_bytes_timeout,omitempty"`
Expand All @@ -119,9 +111,13 @@ type CreateBackendInput struct {
SSLClientKey string `url:"ssl_client_key,omitempty"`
SSLHostname string `url:"ssl_hostname,omitempty"`
SSLSNIHostname string `url:"ssl_sni_hostname,omitempty"`
Shield string `url:"shield,omitempty"`
UseSSL Compatibool `url:"use_ssl,omitempty"`
Weight *uint `url:"weight,omitempty"`
// ServiceID is the ID of the service (required).
ServiceID string
// ServiceVersion is the specific configuration version (required).
ServiceVersion int
Shield string `url:"shield,omitempty"`
UseSSL Compatibool `url:"use_ssl,omitempty"`
Weight *uint `url:"weight,omitempty"`
}

// CreateBackend creates a new Fastly backend.
Expand Down Expand Up @@ -150,14 +146,12 @@ func (c *Client) CreateBackend(i *CreateBackendInput) (*Backend, error) {

// GetBackendInput is used as input to the GetBackend function.
type GetBackendInput struct {
// Name is the name of the backend to fetch.
Name string
// ServiceID is the ID of the service (required).
ServiceID string

// ServiceVersion is the specific configuration version (required).
ServiceVersion int

// Name is the name of the backend to fetch.
Name string
}

// GetBackend gets the backend configuration with the given parameters.
Expand Down Expand Up @@ -190,15 +184,6 @@ func (c *Client) GetBackend(i *GetBackendInput) (*Backend, error) {

// UpdateBackendInput is used as input to the UpdateBackend function.
type UpdateBackendInput struct {
// ServiceID is the ID of the service (required).
ServiceID string

// ServiceVersion is the specific configuration version (required).
ServiceVersion int

// Name is the name of the backend to update.
Name string

Address *string `url:"address,omitempty"`
AutoLoadbalance *Compatibool `url:"auto_loadbalance,omitempty"`
BetweenBytesTimeout *uint `url:"between_bytes_timeout,omitempty"`
Expand All @@ -210,20 +195,26 @@ type UpdateBackendInput struct {
MaxConn *uint `url:"max_conn,omitempty"`
MaxTLSVersion *string `url:"max_tls_version,omitempty"`
MinTLSVersion *string `url:"min_tls_version,omitempty"`
NewName *string `url:"name,omitempty"`
OverrideHost *string `url:"override_host,omitempty"`
Port *uint `url:"port,omitempty"`
RequestCondition *string `url:"request_condition,omitempty"`
SSLCACert *string `url:"ssl_ca_cert,omitempty"`
SSLCertHostname *string `url:"ssl_cert_hostname,omitempty"`
SSLCheckCert *Compatibool `url:"ssl_check_cert,omitempty"`
SSLCiphers *string `url:"ssl_ciphers,omitempty"`
SSLClientCert *string `url:"ssl_client_cert,omitempty"`
SSLClientKey *string `url:"ssl_client_key,omitempty"`
SSLSNIHostname *string `url:"ssl_sni_hostname,omitempty"`
Shield *string `url:"shield,omitempty"`
UseSSL *Compatibool `url:"use_ssl,omitempty"`
Weight *uint `url:"weight,omitempty"`
// Name is the name of the backend to update.
Name string
NewName *string `url:"name,omitempty"`
OverrideHost *string `url:"override_host,omitempty"`
Port *uint `url:"port,omitempty"`
RequestCondition *string `url:"request_condition,omitempty"`
SSLCACert *string `url:"ssl_ca_cert,omitempty"`
SSLCertHostname *string `url:"ssl_cert_hostname,omitempty"`
SSLCheckCert *Compatibool `url:"ssl_check_cert,omitempty"`
SSLCiphers *string `url:"ssl_ciphers,omitempty"`
SSLClientCert *string `url:"ssl_client_cert,omitempty"`
SSLClientKey *string `url:"ssl_client_key,omitempty"`
SSLSNIHostname *string `url:"ssl_sni_hostname,omitempty"`
// ServiceID is the ID of the service (required).
ServiceID string
// ServiceVersion is the specific configuration version (required).
ServiceVersion int
Shield *string `url:"shield,omitempty"`
UseSSL *Compatibool `url:"use_ssl,omitempty"`
Weight *uint `url:"weight,omitempty"`
}

// UpdateBackend updates a specific backend.
Expand Down Expand Up @@ -256,14 +247,12 @@ func (c *Client) UpdateBackend(i *UpdateBackendInput) (*Backend, error) {

// DeleteBackendInput is the input parameter to DeleteBackend.
type DeleteBackendInput struct {
// Name is the name of the backend to delete (required).
Name string
// ServiceID is the ID of the service (required).
ServiceID string

// ServiceVersion is the specific configuration version (required).
ServiceVersion int

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

// DeleteBackend deletes the given backend version.
Expand Down
Loading