diff --git a/fastly/acl.go b/fastly/acl.go index eba234df8..81f68e6f3 100644 --- a/fastly/acl.go +++ b/fastly/acl.go @@ -52,6 +52,7 @@ func (c *Client) ListACLs(i *ListACLsInput) ([]*ACL, error) { if err != nil { return nil, err } + defer resp.Body.Close() var as []*ACL if err := decodeBodyMap(resp.Body, &as); err != nil { @@ -87,6 +88,7 @@ func (c *Client) CreateACL(i *CreateACLInput) (*ACL, error) { if err != nil { return nil, err } + defer resp.Body.Close() var a *ACL if err := decodeBodyMap(resp.Body, &a); err != nil { @@ -126,6 +128,7 @@ func (c *Client) DeleteACL(i *DeleteACLInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { @@ -168,6 +171,7 @@ func (c *Client) GetACL(i *GetACLInput) (*ACL, error) { if err != nil { return nil, err } + defer resp.Body.Close() var a *ACL if err := decodeBodyMap(resp.Body, &a); err != nil { @@ -211,10 +215,10 @@ func (c *Client) UpdateACL(i *UpdateACLInput) (*ACL, error) { path := fmt.Sprintf("/service/%s/version/%d/acl/%s", i.ServiceID, i.ServiceVersion, url.PathEscape(i.Name)) resp, err := c.PutForm(path, i, nil) - if err != nil { return nil, err } + defer resp.Body.Close() var a *ACL if err := decodeBodyMap(resp.Body, &a); err != nil { diff --git a/fastly/acl_entry.go b/fastly/acl_entry.go index 0218511e1..2466c8fe1 100644 --- a/fastly/acl_entry.go +++ b/fastly/acl_entry.go @@ -60,6 +60,7 @@ func (c *Client) ListACLEntries(i *ListACLEntriesInput) ([]*ACLEntry, error) { if err != nil { return nil, err } + defer resp.Body.Close() var es []*ACLEntry if err := decodeBodyMap(resp.Body, &es); err != nil { @@ -108,7 +109,6 @@ func (c *Client) NewListACLEntriesPaginator(i *ListACLEntriesInput) PaginatorACL // listACLEntriesWithPage return a list of entries for an ACL of a given page func (c *Client) listACLEntriesWithPage(i *ListACLEntriesInput, p *ListAclEntriesPaginator) ([]*ACLEntry, error) { - if i.ServiceID == "" { return nil, ErrMissingServiceID } @@ -156,6 +156,7 @@ func (c *Client) listACLEntriesWithPage(i *ListACLEntriesInput, p *ListAclEntrie if err != nil { return nil, err } + defer resp.Body.Close() for _, l := range link.ParseResponse(resp) { // indicates the Link response header contained the next page instruction @@ -211,6 +212,7 @@ func (c *Client) GetACLEntry(i *GetACLEntryInput) (*ACLEntry, error) { if err != nil { return nil, err } + defer resp.Body.Close() var e *ACLEntry if err := decodeBodyMap(resp.Body, &e); err != nil { @@ -253,6 +255,7 @@ func (c *Client) CreateACLEntry(i *CreateACLEntryInput) (*ACLEntry, error) { if err != nil { return nil, err } + defer resp.Body.Close() var e *ACLEntry if err := decodeBodyMap(resp.Body, &e); err != nil { @@ -289,6 +292,7 @@ func (c *Client) DeleteACLEntry(i *DeleteACLEntryInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { @@ -300,7 +304,6 @@ func (c *Client) DeleteACLEntry(i *DeleteACLEntryInput) error { } return nil - } // UpdateACLEntryInput is the input parameter to UpdateACLEntry function. @@ -337,6 +340,7 @@ func (c *Client) UpdateACLEntry(i *UpdateACLEntryInput) (*ACLEntry, error) { if err != nil { return nil, err } + defer resp.Body.Close() var e *ACLEntry if err := decodeBodyMap(resp.Body, &e); err != nil { @@ -380,6 +384,7 @@ func (c *Client) BatchModifyACLEntries(i *BatchModifyACLEntriesInput) error { if err != nil { return err } + defer resp.Body.Close() var batchModifyResult map[string]string if err := decodeBodyMap(resp.Body, &batchModifyResult); err != nil { diff --git a/fastly/backend.go b/fastly/backend.go index 5cc07d3bb..46e7ef557 100644 --- a/fastly/backend.go +++ b/fastly/backend.go @@ -78,6 +78,7 @@ func (c *Client) ListBackends(i *ListBackendsInput) ([]*Backend, error) { if err != nil { return nil, err } + defer resp.Body.Close() var bs []*Backend if err := decodeBodyMap(resp.Body, &bs); err != nil { @@ -142,6 +143,7 @@ func (c *Client) CreateBackend(i *CreateBackendInput) (*Backend, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *Backend if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -181,6 +183,7 @@ func (c *Client) GetBackend(i *GetBackendInput) (*Backend, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *Backend if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -247,6 +250,7 @@ func (c *Client) UpdateBackend(i *UpdateBackendInput) (*Backend, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *Backend if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -286,6 +290,7 @@ func (c *Client) DeleteBackend(i *DeleteBackendInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/bigquery.go b/fastly/bigquery.go index bce2968f7..07efa3fdd 100644 --- a/fastly/bigquery.go +++ b/fastly/bigquery.go @@ -62,6 +62,7 @@ func (c *Client) ListBigQueries(i *ListBigQueriesInput) ([]*BigQuery, error) { if err != nil { return nil, err } + defer resp.Body.Close() var bigQueries []*BigQuery if err := decodeBodyMap(resp.Body, &bigQueries); err != nil { @@ -107,6 +108,7 @@ func (c *Client) CreateBigQuery(i *CreateBigQueryInput) (*BigQuery, error) { if err != nil { return nil, err } + defer resp.Body.Close() var bigQuery *BigQuery if err := decodeBodyMap(resp.Body, &bigQuery); err != nil { @@ -146,6 +148,7 @@ func (c *Client) GetBigQuery(i *GetBigQueryInput) (*BigQuery, error) { if err != nil { return nil, err } + defer resp.Body.Close() var bigQuery *BigQuery if err := decodeBodyMap(resp.Body, &bigQuery); err != nil { @@ -197,6 +200,7 @@ func (c *Client) UpdateBigQuery(i *UpdateBigQueryInput) (*BigQuery, error) { if err != nil { return nil, err } + defer resp.Body.Close() var bigQuery *BigQuery if err := decodeBodyMap(resp.Body, &bigQuery); err != nil { @@ -236,6 +240,7 @@ func (c *Client) DeleteBigQuery(i *DeleteBigQueryInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/billing.go b/fastly/billing.go index 91de1db39..fbc6af6d4 100644 --- a/fastly/billing.go +++ b/fastly/billing.go @@ -72,6 +72,7 @@ func (c *Client) GetBilling(i *GetBillingInput) (*Billing, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *Billing if err := decodeBodyMap(resp.Body, &b); err != nil { diff --git a/fastly/blobstorage.go b/fastly/blobstorage.go index 321ff32fd..a85a29c8f 100644 --- a/fastly/blobstorage.go +++ b/fastly/blobstorage.go @@ -67,6 +67,7 @@ func (c *Client) ListBlobStorages(i *ListBlobStoragesInput) ([]*BlobStorage, err if err != nil { return nil, err } + defer resp.Body.Close() var as []*BlobStorage if err := decodeBodyMap(resp.Body, &as); err != nil { @@ -117,6 +118,7 @@ func (c *Client) CreateBlobStorage(i *CreateBlobStorageInput) (*BlobStorage, err if err != nil { return nil, err } + defer resp.Body.Close() var a *BlobStorage if err := decodeBodyMap(resp.Body, &a); err != nil { @@ -156,6 +158,7 @@ func (c *Client) GetBlobStorage(i *GetBlobStorageInput) (*BlobStorage, error) { if err != nil { return nil, err } + defer resp.Body.Close() var a *BlobStorage if err := decodeBodyMap(resp.Body, &a); err != nil { @@ -212,6 +215,7 @@ func (c *Client) UpdateBlobStorage(i *UpdateBlobStorageInput) (*BlobStorage, err if err != nil { return nil, err } + defer resp.Body.Close() var a *BlobStorage if err := decodeBodyMap(resp.Body, &a); err != nil { @@ -251,6 +255,7 @@ func (c *Client) DeleteBlobStorage(i *DeleteBlobStorageInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/cache_setting.go b/fastly/cache_setting.go index 9fb15e645..e863dde7a 100644 --- a/fastly/cache_setting.go +++ b/fastly/cache_setting.go @@ -71,6 +71,7 @@ func (c *Client) ListCacheSettings(i *ListCacheSettingsInput) ([]*CacheSetting, if err != nil { return nil, err } + defer resp.Body.Close() var cs []*CacheSetting if err := decodeBodyMap(resp.Body, &cs); err != nil { @@ -110,6 +111,7 @@ func (c *Client) CreateCacheSetting(i *CreateCacheSettingInput) (*CacheSetting, if err != nil { return nil, err } + defer resp.Body.Close() var cs *CacheSetting if err := decodeBodyMap(resp.Body, &cs); err != nil { @@ -150,6 +152,7 @@ func (c *Client) GetCacheSetting(i *GetCacheSettingInput) (*CacheSetting, error) if err != nil { return nil, err } + defer resp.Body.Close() var cs *CacheSetting if err := decodeBodyMap(resp.Body, &cs); err != nil { @@ -195,6 +198,7 @@ func (c *Client) UpdateCacheSetting(i *UpdateCacheSettingInput) (*CacheSetting, if err != nil { return nil, err } + defer resp.Body.Close() var cs *CacheSetting if err := decodeBodyMap(resp.Body, &cs); err != nil { @@ -234,6 +238,7 @@ func (c *Client) DeleteCacheSetting(i *DeleteCacheSettingInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/cloudfiles.go b/fastly/cloudfiles.go index 9991f2909..fbfc76b0c 100644 --- a/fastly/cloudfiles.go +++ b/fastly/cloudfiles.go @@ -67,6 +67,7 @@ func (c *Client) ListCloudfiles(i *ListCloudfilesInput) ([]*Cloudfiles, error) { if err != nil { return nil, err } + defer resp.Body.Close() var cloudfiles []*Cloudfiles if err := decodeBodyMap(resp.Body, &cloudfiles); err != nil { @@ -117,6 +118,7 @@ func (c *Client) CreateCloudfiles(i *CreateCloudfilesInput) (*Cloudfiles, error) if err != nil { return nil, err } + defer resp.Body.Close() var cloudfiles *Cloudfiles if err := decodeBodyMap(resp.Body, &cloudfiles); err != nil { @@ -156,6 +158,7 @@ func (c *Client) GetCloudfiles(i *GetCloudfilesInput) (*Cloudfiles, error) { if err != nil { return nil, err } + defer resp.Body.Close() var cloudfiles *Cloudfiles if err := decodeBodyMap(resp.Body, &cloudfiles); err != nil { @@ -212,6 +215,7 @@ func (c *Client) UpdateCloudfiles(i *UpdateCloudfilesInput) (*Cloudfiles, error) if err != nil { return nil, err } + defer resp.Body.Close() var cloudfiles *Cloudfiles if err := decodeBodyMap(resp.Body, &cloudfiles); err != nil { @@ -251,6 +255,7 @@ func (c *Client) DeleteCloudfiles(i *DeleteCloudfilesInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/condition.go b/fastly/condition.go index 7df18e11b..411e5199e 100644 --- a/fastly/condition.go +++ b/fastly/condition.go @@ -56,6 +56,7 @@ func (c *Client) ListConditions(i *ListConditionsInput) ([]*Condition, error) { if err != nil { return nil, err } + defer resp.Body.Close() var cs []*Condition if err := decodeBodyMap(resp.Body, &cs); err != nil { @@ -94,6 +95,7 @@ func (c *Client) CreateCondition(i *CreateConditionInput) (*Condition, error) { if err != nil { return nil, err } + defer resp.Body.Close() var co *Condition if err := decodeBodyMap(resp.Body, &co); err != nil { @@ -133,6 +135,7 @@ func (c *Client) GetCondition(i *GetConditionInput) (*Condition, error) { if err != nil { return nil, err } + defer resp.Body.Close() var co *Condition if err := decodeBodyMap(resp.Body, &co); err != nil { @@ -177,6 +180,7 @@ func (c *Client) UpdateCondition(i *UpdateConditionInput) (*Condition, error) { if err != nil { return nil, err } + defer resp.Body.Close() var co *Condition if err := decodeBodyMap(resp.Body, &co); err != nil { @@ -216,6 +220,7 @@ func (c *Client) DeleteCondition(i *DeleteConditionInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/content.go b/fastly/content.go index bd82d64ae..f24f18767 100644 --- a/fastly/content.go +++ b/fastly/content.go @@ -40,6 +40,7 @@ func (c *Client) EdgeCheck(i *EdgeCheckInput) ([]*EdgeCheck, error) { if err != nil { return nil, err } + defer resp.Body.Close() var e []*EdgeCheck if err := decodeBodyMap(resp.Body, &e); err != nil { diff --git a/fastly/custom_tls_activation.go b/fastly/custom_tls_activation.go index 7aaf62e1c..1395f8845 100644 --- a/fastly/custom_tls_activation.go +++ b/fastly/custom_tls_activation.go @@ -177,6 +177,7 @@ func (c *Client) UpdateTLSActivation(i *UpdateTLSActivationInput) (*TLSActivatio if err != nil { return nil, err } + defer resp.Body.Close() var ta TLSActivation if err := jsonapi.UnmarshalPayload(resp.Body, &ta); err != nil { diff --git a/fastly/custom_tls_certificate.go b/fastly/custom_tls_certificate.go index e48d67f94..ab024db5a 100644 --- a/fastly/custom_tls_certificate.go +++ b/fastly/custom_tls_certificate.go @@ -173,6 +173,7 @@ func (c *Client) UpdateCustomTLSCertificate(i *UpdateCustomTLSCertificateInput) if err != nil { return nil, err } + defer resp.Body.Close() var cc CustomTLSCertificate if err := jsonapi.UnmarshalPayload(resp.Body, &cc); err != nil { diff --git a/fastly/custom_tls_configuration.go b/fastly/custom_tls_configuration.go index 3e5d54574..5ab274fc6 100644 --- a/fastly/custom_tls_configuration.go +++ b/fastly/custom_tls_configuration.go @@ -35,7 +35,6 @@ type ListCustomTLSConfigurationsInput struct { Include string // Include related objects. Optional, comma-separated values. Permitted values: dns_records. PageNumber int // The page index for pagination. PageSize int // The number of keys per page. - } // formatFilters converts user input into query parameters for filtering. @@ -154,6 +153,7 @@ func (c *Client) UpdateCustomTLSConfiguration(i *UpdateCustomTLSConfigurationInp if err != nil { return nil, err } + defer resp.Body.Close() var con CustomTLSConfiguration if err := jsonapi.UnmarshalPayload(resp.Body, &con); err != nil { diff --git a/fastly/custom_tls_domain.go b/fastly/custom_tls_domain.go index b36eef2fd..2efc05149 100644 --- a/fastly/custom_tls_domain.go +++ b/fastly/custom_tls_domain.go @@ -73,6 +73,7 @@ func (c *Client) ListTLSDomains(i *ListTLSDomainsInput) ([]*TLSDomain, error) { if err != nil { return nil, err } + defer r.Body.Close() data, err := jsonapi.UnmarshalManyPayload(r.Body, reflect.TypeOf(new(TLSDomain))) if err != nil { diff --git a/fastly/datacenters.go b/fastly/datacenters.go index 0bf708011..5da68dfee 100644 --- a/fastly/datacenters.go +++ b/fastly/datacenters.go @@ -23,6 +23,8 @@ func (c *Client) AllDatacenters() (datacenters []Datacenter, err error) { if err != nil { return nil, err } + defer resp.Body.Close() + var m []Datacenter if err := decodeBodyMap(resp.Body, &m); err != nil { return nil, err diff --git a/fastly/datadog.go b/fastly/datadog.go index 7a591c0b7..cd014e3c2 100644 --- a/fastly/datadog.go +++ b/fastly/datadog.go @@ -58,6 +58,7 @@ func (c *Client) ListDatadog(i *ListDatadogInput) ([]*Datadog, error) { if err != nil { return nil, err } + defer resp.Body.Close() var d []*Datadog if err := decodeBodyMap(resp.Body, &d); err != nil { @@ -103,6 +104,7 @@ func (c *Client) CreateDatadog(i *CreateDatadogInput) (*Datadog, error) { if err != nil { return nil, err } + defer resp.Body.Close() var d *Datadog if err := decodeBodyMap(resp.Body, &d); err != nil { @@ -142,6 +144,7 @@ func (c *Client) GetDatadog(i *GetDatadogInput) (*Datadog, error) { if err != nil { return nil, err } + defer resp.Body.Close() var d *Datadog if err := decodeBodyMap(resp.Body, &d); err != nil { @@ -193,6 +196,7 @@ func (c *Client) UpdateDatadog(i *UpdateDatadogInput) (*Datadog, error) { if err != nil { return nil, err } + defer resp.Body.Close() var d *Datadog if err := decodeBodyMap(resp.Body, &d); err != nil { @@ -232,6 +236,7 @@ func (c *Client) DeleteDatadog(i *DeleteDatadogInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/dictionary.go b/fastly/dictionary.go index f186bd62c..63ad86f1b 100644 --- a/fastly/dictionary.go +++ b/fastly/dictionary.go @@ -54,6 +54,7 @@ func (c *Client) ListDictionaries(i *ListDictionariesInput) ([]*Dictionary, erro if err != nil { return nil, err } + defer resp.Body.Close() var bs []*Dictionary if err := decodeBodyMap(resp.Body, &bs); err != nil { @@ -90,6 +91,7 @@ func (c *Client) CreateDictionary(i *CreateDictionaryInput) (*Dictionary, error) if err != nil { return nil, err } + defer resp.Body.Close() var b *Dictionary if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -129,6 +131,7 @@ func (c *Client) GetDictionary(i *GetDictionaryInput) (*Dictionary, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *Dictionary if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -171,6 +174,7 @@ func (c *Client) UpdateDictionary(i *UpdateDictionaryInput) (*Dictionary, error) if err != nil { return nil, err } + defer resp.Body.Close() var b *Dictionary if err := decodeBodyMap(resp.Body, &b); err != nil { diff --git a/fastly/dictionary_info.go b/fastly/dictionary_info.go index ef8e195c6..c36a4cbb7 100644 --- a/fastly/dictionary_info.go +++ b/fastly/dictionary_info.go @@ -48,6 +48,7 @@ func (c *Client) GetDictionaryInfo(i *GetDictionaryInfoInput) (*DictionaryInfo, if err != nil { return nil, err } + defer resp.Body.Close() var b *DictionaryInfo if err := decodeBodyMap(resp.Body, &b); err != nil { diff --git a/fastly/dictionary_item.go b/fastly/dictionary_item.go index e85e49a2c..f7e8df588 100644 --- a/fastly/dictionary_item.go +++ b/fastly/dictionary_item.go @@ -60,6 +60,7 @@ func (c *Client) ListDictionaryItems(i *ListDictionaryItemsInput) ([]*Dictionary if err != nil { return nil, err } + defer resp.Body.Close() var bs []*DictionaryItem if err := decodeBodyMap(resp.Body, &bs); err != nil { @@ -153,6 +154,7 @@ func (c *Client) listDictionaryItemsWithPage(i *ListDictionaryItemsInput, p *Lis if err != nil { return nil, err } + defer resp.Body.Close() for _, l := range link.ParseResponse(resp) { // indicates the Link response header contained the next page instruction @@ -207,6 +209,7 @@ func (c *Client) CreateDictionaryItem(i *CreateDictionaryItemInput) (*Dictionary if err != nil { return nil, err } + defer resp.Body.Close() var b *DictionaryItem if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -217,7 +220,6 @@ func (c *Client) CreateDictionaryItem(i *CreateDictionaryItemInput) (*Dictionary // CreateDictionaryItems creates new Fastly dictionary items from a slice. func (c *Client) CreateDictionaryItems(i []CreateDictionaryItemInput) ([]DictionaryItem, error) { - var b []DictionaryItem for _, cdii := range i { di, err := c.CreateDictionaryItem(&cdii) @@ -260,6 +262,7 @@ func (c *Client) GetDictionaryItem(i *GetDictionaryItemInput) (*DictionaryItem, if err != nil { return nil, err } + defer resp.Body.Close() var b *DictionaryItem if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -302,6 +305,7 @@ func (c *Client) UpdateDictionaryItem(i *UpdateDictionaryItemInput) (*Dictionary if err != nil { return nil, err } + defer resp.Body.Close() var b *DictionaryItem if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -327,7 +331,6 @@ type BatchDictionaryItem struct { } func (c *Client) BatchModifyDictionaryItems(i *BatchModifyDictionaryItemsInput) error { - if i.ServiceID == "" { return ErrMissingServiceID } @@ -345,6 +348,7 @@ func (c *Client) BatchModifyDictionaryItems(i *BatchModifyDictionaryItemsInput) if err != nil { return err } + defer resp.Body.Close() var batchModifyResult map[string]string if err := decodeBodyMap(resp.Body, &batchModifyResult); err != nil { diff --git a/fastly/diff.go b/fastly/diff.go index 9fb6bcb61..c77d9862a 100644 --- a/fastly/diff.go +++ b/fastly/diff.go @@ -48,6 +48,7 @@ func (c *Client) GetDiff(i *GetDiffInput) (*Diff, error) { if err != nil { return nil, err } + defer resp.Body.Close() var d *Diff if err := decodeBodyMap(resp.Body, &d); err != nil { diff --git a/fastly/digitalocean.go b/fastly/digitalocean.go index 81281863b..1c2ee2429 100644 --- a/fastly/digitalocean.go +++ b/fastly/digitalocean.go @@ -67,6 +67,7 @@ func (c *Client) ListDigitalOceans(i *ListDigitalOceansInput) ([]*DigitalOcean, if err != nil { return nil, err } + defer resp.Body.Close() var digitaloceans []*DigitalOcean if err := decodeBodyMap(resp.Body, &digitaloceans); err != nil { @@ -117,6 +118,7 @@ func (c *Client) CreateDigitalOcean(i *CreateDigitalOceanInput) (*DigitalOcean, if err != nil { return nil, err } + defer resp.Body.Close() var digitalocean *DigitalOcean if err := decodeBodyMap(resp.Body, &digitalocean); err != nil { @@ -156,6 +158,7 @@ func (c *Client) GetDigitalOcean(i *GetDigitalOceanInput) (*DigitalOcean, error) if err != nil { return nil, err } + defer resp.Body.Close() var digitalocean *DigitalOcean if err := decodeBodyMap(resp.Body, &digitalocean); err != nil { @@ -212,6 +215,7 @@ func (c *Client) UpdateDigitalOcean(i *UpdateDigitalOceanInput) (*DigitalOcean, if err != nil { return nil, err } + defer resp.Body.Close() var digitalocean *DigitalOcean if err := decodeBodyMap(resp.Body, &digitalocean); err != nil { @@ -251,6 +255,7 @@ func (c *Client) DeleteDigitalOcean(i *DeleteDigitalOceanInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/director.go b/fastly/director.go index aede02b23..6cf55a10b 100644 --- a/fastly/director.go +++ b/fastly/director.go @@ -76,6 +76,7 @@ func (c *Client) ListDirectors(i *ListDirectorsInput) ([]*Director, error) { if err != nil { return nil, err } + defer resp.Body.Close() var ds []*Director if err := decodeBodyMap(resp.Body, &ds); err != nil { @@ -117,6 +118,7 @@ func (c *Client) CreateDirector(i *CreateDirectorInput) (*Director, error) { if err != nil { return nil, err } + defer resp.Body.Close() var d *Director if err := decodeBodyMap(resp.Body, &d); err != nil { @@ -156,6 +158,7 @@ func (c *Client) GetDirector(i *GetDirectorInput) (*Director, error) { if err != nil { return nil, err } + defer resp.Body.Close() var d *Director if err := decodeBodyMap(resp.Body, &d); err != nil { @@ -203,6 +206,7 @@ func (c *Client) UpdateDirector(i *UpdateDirectorInput) (*Director, error) { if err != nil { return nil, err } + defer resp.Body.Close() var d *Director if err := decodeBodyMap(resp.Body, &d); err != nil { @@ -242,6 +246,7 @@ func (c *Client) DeleteDirector(i *DeleteDirectorInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/director_backend.go b/fastly/director_backend.go index e69eb804f..f2bb006c2 100644 --- a/fastly/director_backend.go +++ b/fastly/director_backend.go @@ -55,10 +55,12 @@ func (c *Client) CreateDirectorBackend(i *CreateDirectorBackendInput) (*Director path := fmt.Sprintf("/service/%s/version/%d/director/%s/backend/%s", i.ServiceID, i.ServiceVersion, url.PathEscape(i.Director), url.PathEscape(i.Backend)) + resp, err := c.PostForm(path, i, nil) if err != nil { return nil, err } + defer resp.Body.Close() var b *DirectorBackend if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -102,10 +104,12 @@ func (c *Client) GetDirectorBackend(i *GetDirectorBackendInput) (*DirectorBacken path := fmt.Sprintf("/service/%s/version/%d/director/%s/backend/%s", i.ServiceID, i.ServiceVersion, url.PathEscape(i.Director), url.PathEscape(i.Backend)) + resp, err := c.Get(path, nil) if err != nil { return nil, err } + defer resp.Body.Close() var b *DirectorBackend if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -149,10 +153,12 @@ func (c *Client) DeleteDirectorBackend(i *DeleteDirectorBackendInput) error { path := fmt.Sprintf("/service/%s/version/%d/director/%s/backend/%s", i.ServiceID, i.ServiceVersion, url.PathEscape(i.Director), url.PathEscape(i.Backend)) + resp, err := c.Delete(path, nil) if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/domain.go b/fastly/domain.go index b69b44c4f..9ff088838 100644 --- a/fastly/domain.go +++ b/fastly/domain.go @@ -55,6 +55,7 @@ func (c *Client) ListDomains(i *ListDomainsInput) ([]*Domain, error) { if err != nil { return nil, err } + defer resp.Body.Close() var ds []*Domain if err := decodeBodyMap(resp.Body, &ds); err != nil { @@ -94,6 +95,7 @@ func (c *Client) CreateDomain(i *CreateDomainInput) (*Domain, error) { if err != nil { return nil, err } + defer resp.Body.Close() var d *Domain if err := decodeBodyMap(resp.Body, &d); err != nil { @@ -133,6 +135,7 @@ func (c *Client) GetDomain(i *GetDomainInput) (*Domain, error) { if err != nil { return nil, err } + defer resp.Body.Close() var d *Domain if err := decodeBodyMap(resp.Body, &d); err != nil { @@ -183,6 +186,7 @@ func (c *Client) UpdateDomain(i *UpdateDomainInput) (*Domain, error) { if err != nil { return nil, err } + defer resp.Body.Close() var d *Domain if err := decodeBodyMap(resp.Body, &d); err != nil { diff --git a/fastly/elasticsearch.go b/fastly/elasticsearch.go index bb18721a1..71d6cfb70 100644 --- a/fastly/elasticsearch.go +++ b/fastly/elasticsearch.go @@ -67,6 +67,7 @@ func (c *Client) ListElasticsearch(i *ListElasticsearchInput) ([]*Elasticsearch, if err != nil { return nil, err } + defer resp.Body.Close() var elasticsearch []*Elasticsearch if err := decodeBodyMap(resp.Body, &elasticsearch); err != nil { @@ -117,6 +118,7 @@ func (c *Client) CreateElasticsearch(i *CreateElasticsearchInput) (*Elasticsearc if err != nil { return nil, err } + defer resp.Body.Close() var elasticsearch *Elasticsearch if err := decodeBodyMap(resp.Body, &elasticsearch); err != nil { @@ -155,6 +157,7 @@ func (c *Client) GetElasticsearch(i *GetElasticsearchInput) (*Elasticsearch, err if err != nil { return nil, err } + defer resp.Body.Close() var es *Elasticsearch if err := decodeBodyMap(resp.Body, &es); err != nil { @@ -210,6 +213,7 @@ func (c *Client) UpdateElasticsearch(i *UpdateElasticsearchInput) (*Elasticsearc if err != nil { return nil, err } + defer resp.Body.Close() var es *Elasticsearch if err := decodeBodyMap(resp.Body, &es); err != nil { @@ -247,6 +251,7 @@ func (c *Client) DeleteElasticsearch(i *DeleteElasticsearchInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/erl.go b/fastly/erl.go index 6111135fd..d60fd6261 100644 --- a/fastly/erl.go +++ b/fastly/erl.go @@ -124,6 +124,7 @@ func (c *Client) ListERLs(i *ListERLsInput) ([]*ERL, error) { if err != nil { return nil, err } + defer resp.Body.Close() var erls []*ERL if err := decodeBodyMap(resp.Body, &erls); err != nil { @@ -162,6 +163,7 @@ func (c *Client) CreateERL(i *CreateERLInput) (*ERL, error) { if err != nil { return nil, err } + defer resp.Body.Close() var erl *ERL if err := decodeBodyMap(resp.Body, &erl); err != nil { @@ -195,6 +197,7 @@ func (c *Client) DeleteERL(i *DeleteERLInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { @@ -231,6 +234,7 @@ func (c *Client) GetERL(i *GetERLInput) (*ERL, error) { if err != nil { return nil, err } + defer resp.Body.Close() var erl *ERL if err := decodeBodyMap(resp.Body, &erl); err != nil { @@ -272,6 +276,7 @@ func (c *Client) UpdateERL(i *UpdateERLInput) (*ERL, error) { if err != nil { return nil, err } + defer resp.Body.Close() var erl *ERL if err := decodeBodyMap(resp.Body, &erl); err != nil { diff --git a/fastly/event_logs.go b/fastly/event_logs.go index daf35dffb..7bb179b59 100644 --- a/fastly/event_logs.go +++ b/fastly/event_logs.go @@ -76,15 +76,15 @@ func (c *Client) GetAPIEvents(i *GetAPIEventsFilterInput) (GetAPIEventsResponse, Links: EventsPaginationInfo{}, } - var path = "/events" + path := "/events" filters := &RequestOptions{Params: i.formatEventFilters()} resp, err := c.Get(path, filters) - if err != nil { return eventsResponse, err } + defer resp.Body.Close() err = c.interpretAPIEventsPage(&eventsResponse, i.PageNumber, resp) // NOTE: It's possible for eventsResponse to be partially completed before an error @@ -111,6 +111,7 @@ func (c *Client) GetAPIEvent(i *GetAPIEventInput) (*Event, error) { if err != nil { return nil, err } + defer resp.Body.Close() var event Event if err := jsonapi.UnmarshalPayload(resp.Body, &event); err != nil { @@ -150,6 +151,7 @@ func (c *Client) interpretAPIEventsPage(answer *GetAPIEventsResponse, pageNum in if err != nil { return err } + defer resp.Body.Close() c.interpretAPIEventsPage(answer, pageNum, resp) } return nil @@ -200,7 +202,6 @@ func (i *GetAPIEventsFilterInput) formatEventFilters() map[string]string { result[key] = strconv.Itoa(value.(int)) } } - } return result } diff --git a/fastly/ftp.go b/fastly/ftp.go index 447c9004a..ddef91181 100644 --- a/fastly/ftp.go +++ b/fastly/ftp.go @@ -67,6 +67,7 @@ func (c *Client) ListFTPs(i *ListFTPsInput) ([]*FTP, error) { if err != nil { return nil, err } + defer resp.Body.Close() var ftps []*FTP if err := decodeBodyMap(resp.Body, &ftps); err != nil { @@ -117,6 +118,7 @@ func (c *Client) CreateFTP(i *CreateFTPInput) (*FTP, error) { if err != nil { return nil, err } + defer resp.Body.Close() var ftp *FTP if err := decodeBodyMap(resp.Body, &ftp); err != nil { @@ -156,6 +158,7 @@ func (c *Client) GetFTP(i *GetFTPInput) (*FTP, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *FTP if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -212,6 +215,7 @@ func (c *Client) UpdateFTP(i *UpdateFTPInput) (*FTP, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *FTP if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -251,6 +255,7 @@ func (c *Client) DeleteFTP(i *DeleteFTPInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/gcs.go b/fastly/gcs.go index 955fc69a8..2ea1e0c00 100644 --- a/fastly/gcs.go +++ b/fastly/gcs.go @@ -115,6 +115,7 @@ func (c *Client) CreateGCS(i *CreateGCSInput) (*GCS, error) { if err != nil { return nil, err } + defer resp.Body.Close() var gcs *GCS if err := decodeBodyMap(resp.Body, &gcs); err != nil { @@ -154,6 +155,7 @@ func (c *Client) GetGCS(i *GetGCSInput) (*GCS, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *GCS if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -209,6 +211,7 @@ func (c *Client) UpdateGCS(i *UpdateGCSInput) (*GCS, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *GCS if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -248,6 +251,7 @@ func (c *Client) DeleteGCS(i *DeleteGCSInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/gzip.go b/fastly/gzip.go index bde657dc2..f7b1dd2f4 100644 --- a/fastly/gzip.go +++ b/fastly/gzip.go @@ -55,6 +55,7 @@ func (c *Client) ListGzips(i *ListGzipsInput) ([]*Gzip, error) { if err != nil { return nil, err } + defer resp.Body.Close() var gzips []*Gzip if err := decodeBodyMap(resp.Body, &gzips); err != nil { @@ -93,6 +94,7 @@ func (c *Client) CreateGzip(i *CreateGzipInput) (*Gzip, error) { if err != nil { return nil, err } + defer resp.Body.Close() var gzip *Gzip if err := decodeBodyMap(resp.Body, &gzip); err != nil { @@ -132,6 +134,7 @@ func (c *Client) GetGzip(i *GetGzipInput) (*Gzip, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *Gzip if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -176,6 +179,7 @@ func (c *Client) UpdateGzip(i *UpdateGzipInput) (*Gzip, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *Gzip if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -215,6 +219,7 @@ func (c *Client) DeleteGzip(i *DeleteGzipInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/header.go b/fastly/header.go index b6106ed39..678a2b9a3 100644 --- a/fastly/header.go +++ b/fastly/header.go @@ -164,6 +164,7 @@ func (c *Client) CreateHeader(i *CreateHeaderInput) (*Header, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *Header if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -203,6 +204,7 @@ func (c *Client) GetHeader(i *GetHeaderInput) (*Header, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *Header if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -255,6 +257,7 @@ func (c *Client) UpdateHeader(i *UpdateHeaderInput) (*Header, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *Header if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -294,6 +297,7 @@ func (c *Client) DeleteHeader(i *DeleteHeaderInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/health_check.go b/fastly/health_check.go index 73a13b398..5182835f2 100644 --- a/fastly/health_check.go +++ b/fastly/health_check.go @@ -110,6 +110,7 @@ func (c *Client) CreateHealthCheck(i *CreateHealthCheckInput) (*HealthCheck, err if err != nil { return nil, err } + defer resp.Body.Close() var h *HealthCheck if err := decodeBodyMap(resp.Body, &h); err != nil { @@ -149,6 +150,7 @@ func (c *Client) GetHealthCheck(i *GetHealthCheckInput) (*HealthCheck, error) { if err != nil { return nil, err } + defer resp.Body.Close() var h *HealthCheck if err := decodeBodyMap(resp.Body, &h); err != nil { @@ -201,6 +203,7 @@ func (c *Client) UpdateHealthCheck(i *UpdateHealthCheckInput) (*HealthCheck, err if err != nil { return nil, err } + defer resp.Body.Close() var h *HealthCheck if err := decodeBodyMap(resp.Body, &h); err != nil { @@ -240,6 +243,7 @@ func (c *Client) DeleteHealthCheck(i *DeleteHealthCheckInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/heroku.go b/fastly/heroku.go index fa9904c68..9802c908e 100644 --- a/fastly/heroku.go +++ b/fastly/heroku.go @@ -99,6 +99,7 @@ func (c *Client) CreateHeroku(i *CreateHerokuInput) (*Heroku, error) { if err != nil { return nil, err } + defer resp.Body.Close() var h *Heroku if err := decodeBodyMap(resp.Body, &h); err != nil { @@ -138,6 +139,7 @@ func (c *Client) GetHeroku(i *GetHerokuInput) (*Heroku, error) { if err != nil { return nil, err } + defer resp.Body.Close() var h *Heroku if err := decodeBodyMap(resp.Body, &h); err != nil { @@ -185,6 +187,7 @@ func (c *Client) UpdateHeroku(i *UpdateHerokuInput) (*Heroku, error) { if err != nil { return nil, err } + defer resp.Body.Close() var h *Heroku if err := decodeBodyMap(resp.Body, &h); err != nil { @@ -224,6 +227,7 @@ func (c *Client) DeleteHeroku(i *DeleteHerokuInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/honeycomb.go b/fastly/honeycomb.go index 04be23f1c..5ead1edd3 100644 --- a/fastly/honeycomb.go +++ b/fastly/honeycomb.go @@ -58,6 +58,7 @@ func (c *Client) ListHoneycombs(i *ListHoneycombsInput) ([]*Honeycomb, error) { if err != nil { return nil, err } + defer resp.Body.Close() var hs []*Honeycomb if err := decodeBodyMap(resp.Body, &hs); err != nil { @@ -103,6 +104,7 @@ func (c *Client) CreateHoneycomb(i *CreateHoneycombInput) (*Honeycomb, error) { if err != nil { return nil, err } + defer resp.Body.Close() var h *Honeycomb if err := decodeBodyMap(resp.Body, &h); err != nil { @@ -142,6 +144,7 @@ func (c *Client) GetHoneycomb(i *GetHoneycombInput) (*Honeycomb, error) { if err != nil { return nil, err } + defer resp.Body.Close() var h *Honeycomb if err := decodeBodyMap(resp.Body, &h); err != nil { @@ -193,6 +196,7 @@ func (c *Client) UpdateHoneycomb(i *UpdateHoneycombInput) (*Honeycomb, error) { if err != nil { return nil, err } + defer resp.Body.Close() var h *Honeycomb if err := decodeBodyMap(resp.Body, &h); err != nil { @@ -232,6 +236,7 @@ func (c *Client) DeleteHoneycomb(i *DeleteHoneycombInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/https.go b/fastly/https.go index e973e4f2c..59fde498a 100644 --- a/fastly/https.go +++ b/fastly/https.go @@ -69,6 +69,7 @@ func (c *Client) ListHTTPS(i *ListHTTPSInput) ([]*HTTPS, error) { if err != nil { return nil, err } + defer resp.Body.Close() var https []*HTTPS if err := decodeBodyMap(resp.Body, &https); err != nil { @@ -121,6 +122,7 @@ func (c *Client) CreateHTTPS(i *CreateHTTPSInput) (*HTTPS, error) { if err != nil { return nil, err } + defer resp.Body.Close() var https *HTTPS if err := decodeBodyMap(resp.Body, &https); err != nil { @@ -159,6 +161,7 @@ func (c *Client) GetHTTPS(i *GetHTTPSInput) (*HTTPS, error) { if err != nil { return nil, err } + defer resp.Body.Close() var h *HTTPS if err := decodeBodyMap(resp.Body, &h); err != nil { @@ -216,6 +219,7 @@ func (c *Client) UpdateHTTPS(i *UpdateHTTPSInput) (*HTTPS, error) { if err != nil { return nil, err } + defer resp.Body.Close() var h *HTTPS if err := decodeBodyMap(resp.Body, &h); err != nil { @@ -253,6 +257,7 @@ func (c *Client) DeleteHTTPS(i *DeleteHTTPSInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/ip.go b/fastly/ip.go index e7c445879..b5903d668 100644 --- a/fastly/ip.go +++ b/fastly/ip.go @@ -9,6 +9,7 @@ func (c *Client) AllIPs() (v4, v6 IPAddrs, err error) { if err != nil { return nil, nil, err } + defer resp.Body.Close() var m map[string][]string if err := decodeBodyMap(resp.Body, &m); err != nil { diff --git a/fastly/kafka.go b/fastly/kafka.go index b250c862d..08923e104 100644 --- a/fastly/kafka.go +++ b/fastly/kafka.go @@ -70,6 +70,7 @@ func (c *Client) ListKafkas(i *ListKafkasInput) ([]*Kafka, error) { if err != nil { return nil, err } + defer resp.Body.Close() var k []*Kafka if err := decodeBodyMap(resp.Body, &k); err != nil { @@ -123,6 +124,7 @@ func (c *Client) CreateKafka(i *CreateKafkaInput) (*Kafka, error) { if err != nil { return nil, err } + defer resp.Body.Close() var k *Kafka if err := decodeBodyMap(resp.Body, &k); err != nil { @@ -162,6 +164,7 @@ func (c *Client) GetKafka(i *GetKafkaInput) (*Kafka, error) { if err != nil { return nil, err } + defer resp.Body.Close() var k *Kafka if err := decodeBodyMap(resp.Body, &k); err != nil { @@ -221,6 +224,7 @@ func (c *Client) UpdateKafka(i *UpdateKafkaInput) (*Kafka, error) { if err != nil { return nil, err } + defer resp.Body.Close() var k *Kafka if err := decodeBodyMap(resp.Body, &k); err != nil { @@ -260,6 +264,7 @@ func (c *Client) DeleteKafka(i *DeleteKafkaInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/kinesis.go b/fastly/kinesis.go index 292b2ba75..2d5f08b37 100644 --- a/fastly/kinesis.go +++ b/fastly/kinesis.go @@ -61,6 +61,7 @@ func (c *Client) ListKinesis(i *ListKinesisInput) ([]*Kinesis, error) { if err != nil { return nil, err } + defer resp.Body.Close() var kineses []*Kinesis if err := decodeBodyMap(resp.Body, &kineses); err != nil { @@ -105,6 +106,7 @@ func (c *Client) CreateKinesis(i *CreateKinesisInput) (*Kinesis, error) { if err != nil { return nil, err } + defer resp.Body.Close() var kinesis *Kinesis if err := decodeBodyMap(resp.Body, &kinesis); err != nil { @@ -144,6 +146,7 @@ func (c *Client) GetKinesis(i *GetKinesisInput) (*Kinesis, error) { if err != nil { return nil, err } + defer resp.Body.Close() var kinesis *Kinesis if err := decodeBodyMap(resp.Body, &kinesis); err != nil { @@ -194,6 +197,7 @@ func (c *Client) UpdateKinesis(i *UpdateKinesisInput) (*Kinesis, error) { if err != nil { return nil, err } + defer resp.Body.Close() var kinesis *Kinesis if err := decodeBodyMap(resp.Body, &kinesis); err != nil { @@ -233,6 +237,7 @@ func (c *Client) DeleteKinesis(i *DeleteKinesisInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/logentries.go b/fastly/logentries.go index 5c732af3d..9c5dd490a 100644 --- a/fastly/logentries.go +++ b/fastly/logentries.go @@ -60,6 +60,7 @@ func (c *Client) ListLogentries(i *ListLogentriesInput) ([]*Logentries, error) { if err != nil { return nil, err } + defer resp.Body.Close() var ls []*Logentries if err := decodeBodyMap(resp.Body, &ls); err != nil { @@ -103,6 +104,7 @@ func (c *Client) CreateLogentries(i *CreateLogentriesInput) (*Logentries, error) if err != nil { return nil, err } + defer resp.Body.Close() var l *Logentries if err := decodeBodyMap(resp.Body, &l); err != nil { @@ -142,6 +144,7 @@ func (c *Client) GetLogentries(i *GetLogentriesInput) (*Logentries, error) { if err != nil { return nil, err } + defer resp.Body.Close() var l *Logentries if err := decodeBodyMap(resp.Body, &l); err != nil { @@ -191,6 +194,7 @@ func (c *Client) UpdateLogentries(i *UpdateLogentriesInput) (*Logentries, error) if err != nil { return nil, err } + defer resp.Body.Close() var l *Logentries if err := decodeBodyMap(resp.Body, &l); err != nil { @@ -230,6 +234,7 @@ func (c *Client) DeleteLogentries(i *DeleteLogentriesInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/loggly.go b/fastly/loggly.go index 2f29b3560..309a71bbd 100644 --- a/fastly/loggly.go +++ b/fastly/loggly.go @@ -57,6 +57,7 @@ func (c *Client) ListLoggly(i *ListLogglyInput) ([]*Loggly, error) { if err != nil { return nil, err } + defer resp.Body.Close() var ls []*Loggly if err := decodeBodyMap(resp.Body, &ls); err != nil { @@ -97,6 +98,7 @@ func (c *Client) CreateLoggly(i *CreateLogglyInput) (*Loggly, error) { if err != nil { return nil, err } + defer resp.Body.Close() var l *Loggly if err := decodeBodyMap(resp.Body, &l); err != nil { @@ -136,6 +138,7 @@ func (c *Client) GetLoggly(i *GetLogglyInput) (*Loggly, error) { if err != nil { return nil, err } + defer resp.Body.Close() var l *Loggly if err := decodeBodyMap(resp.Body, &l); err != nil { @@ -182,6 +185,7 @@ func (c *Client) UpdateLoggly(i *UpdateLogglyInput) (*Loggly, error) { if err != nil { return nil, err } + defer resp.Body.Close() var l *Loggly if err := decodeBodyMap(resp.Body, &l); err != nil { @@ -221,6 +225,7 @@ func (c *Client) DeleteLoggly(i *DeleteLogglyInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/logshuttle.go b/fastly/logshuttle.go index ba867e50f..061412330 100644 --- a/fastly/logshuttle.go +++ b/fastly/logshuttle.go @@ -58,6 +58,7 @@ func (c *Client) ListLogshuttles(i *ListLogshuttlesInput) ([]*Logshuttle, error) if err != nil { return nil, err } + defer resp.Body.Close() var ls []*Logshuttle if err := decodeBodyMap(resp.Body, &ls); err != nil { @@ -99,6 +100,7 @@ func (c *Client) CreateLogshuttle(i *CreateLogshuttleInput) (*Logshuttle, error) if err != nil { return nil, err } + defer resp.Body.Close() var l *Logshuttle if err := decodeBodyMap(resp.Body, &l); err != nil { @@ -138,6 +140,7 @@ func (c *Client) GetLogshuttle(i *GetLogshuttleInput) (*Logshuttle, error) { if err != nil { return nil, err } + defer resp.Body.Close() var l *Logshuttle if err := decodeBodyMap(resp.Body, &l); err != nil { @@ -185,6 +188,7 @@ func (c *Client) UpdateLogshuttle(i *UpdateLogshuttleInput) (*Logshuttle, error) if err != nil { return nil, err } + defer resp.Body.Close() var l *Logshuttle if err := decodeBodyMap(resp.Body, &l); err != nil { @@ -224,6 +228,7 @@ func (c *Client) DeleteLogshuttle(i *DeleteLogshuttleInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/managed_logging.go b/fastly/managed_logging.go index 2b292b841..71f4ef66b 100644 --- a/fastly/managed_logging.go +++ b/fastly/managed_logging.go @@ -56,6 +56,7 @@ func (c *Client) CreateManagedLogging(i *CreateManagedLoggingInput) (*ManagedLog } return nil, err } + defer resp.Body.Close() var m *ManagedLogging if err := decodeBodyMap(resp.Body, &m); err != nil { diff --git a/fastly/newrelic.go b/fastly/newrelic.go index bc64787ff..c2207ae46 100644 --- a/fastly/newrelic.go +++ b/fastly/newrelic.go @@ -58,6 +58,7 @@ func (c *Client) ListNewRelic(i *ListNewRelicInput) ([]*NewRelic, error) { if err != nil { return nil, err } + defer resp.Body.Close() var n []*NewRelic if err := decodeBodyMap(resp.Body, &n); err != nil { @@ -103,6 +104,7 @@ func (c *Client) CreateNewRelic(i *CreateNewRelicInput) (*NewRelic, error) { if err != nil { return nil, err } + defer resp.Body.Close() var n *NewRelic if err := decodeBodyMap(resp.Body, &n); err != nil { @@ -142,6 +144,7 @@ func (c *Client) GetNewRelic(i *GetNewRelicInput) (*NewRelic, error) { if err != nil { return nil, err } + defer resp.Body.Close() var n *NewRelic if err := decodeBodyMap(resp.Body, &n); err != nil { @@ -193,6 +196,7 @@ func (c *Client) UpdateNewRelic(i *UpdateNewRelicInput) (*NewRelic, error) { if err != nil { return nil, err } + defer resp.Body.Close() var n *NewRelic if err := decodeBodyMap(resp.Body, &n); err != nil { @@ -232,6 +236,7 @@ func (c *Client) DeleteNewRelic(i *DeleteNewRelicInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/openstack.go b/fastly/openstack.go index a00adcf19..123b765d3 100644 --- a/fastly/openstack.go +++ b/fastly/openstack.go @@ -67,6 +67,7 @@ func (c *Client) ListOpenstack(i *ListOpenstackInput) ([]*Openstack, error) { if err != nil { return nil, err } + defer resp.Body.Close() var openstacks []*Openstack if err := decodeBodyMap(resp.Body, &openstacks); err != nil { @@ -117,6 +118,7 @@ func (c *Client) CreateOpenstack(i *CreateOpenstackInput) (*Openstack, error) { if err != nil { return nil, err } + defer resp.Body.Close() var openstack *Openstack if err := decodeBodyMap(resp.Body, &openstack); err != nil { @@ -156,6 +158,7 @@ func (c *Client) GetOpenstack(i *GetOpenstackInput) (*Openstack, error) { if err != nil { return nil, err } + defer resp.Body.Close() var openstack *Openstack if err := decodeBodyMap(resp.Body, &openstack); err != nil { @@ -212,6 +215,7 @@ func (c *Client) UpdateOpenstack(i *UpdateOpenstackInput) (*Openstack, error) { if err != nil { return nil, err } + defer resp.Body.Close() var openstack *Openstack if err := decodeBodyMap(resp.Body, &openstack); err != nil { @@ -251,6 +255,7 @@ func (c *Client) DeleteOpenstack(i *DeleteOpenstackInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/package.go b/fastly/package.go index 6434e11e1..429992e1b 100644 --- a/fastly/package.go +++ b/fastly/package.go @@ -49,6 +49,7 @@ func (c *Client) GetPackage(i *GetPackageInput) (*Package, error) { if err != nil { return nil, err } + defer resp.Body.Close() return PopulatePackage(resp.Body) } @@ -67,7 +68,6 @@ type UpdatePackageInput struct { // UpdatePackage updates a package for a specific version. func (c *Client) UpdatePackage(i *UpdatePackageInput) (*Package, error) { - urlPath, err := MakePackagePath(i.ServiceID, i.ServiceVersion) if err != nil { return nil, err @@ -77,6 +77,7 @@ func (c *Client) UpdatePackage(i *UpdatePackageInput) (*Package, error) { if err != nil { return nil, err } + defer resp.Body.Close() return PopulatePackage(resp.Body) } diff --git a/fastly/papertrail.go b/fastly/papertrail.go index 5f4379304..661e29988 100644 --- a/fastly/papertrail.go +++ b/fastly/papertrail.go @@ -58,6 +58,7 @@ func (c *Client) ListPapertrails(i *ListPapertrailsInput) ([]*Papertrail, error) if err != nil { return nil, err } + defer resp.Body.Close() var ps []*Papertrail if err := decodeBodyMap(resp.Body, &ps); err != nil { @@ -102,6 +103,7 @@ func (c *Client) CreatePapertrail(i *CreatePapertrailInput) (*Papertrail, error) if err != nil { return nil, err } + defer resp.Body.Close() var p *Papertrail if err := decodeBodyMap(resp.Body, &p); err != nil { @@ -141,6 +143,7 @@ func (c *Client) GetPapertrail(i *GetPapertrailInput) (*Papertrail, error) { if err != nil { return nil, err } + defer resp.Body.Close() var p *Papertrail if err := decodeBodyMap(resp.Body, &p); err != nil { @@ -191,6 +194,7 @@ func (c *Client) UpdatePapertrail(i *UpdatePapertrailInput) (*Papertrail, error) if err != nil { return nil, err } + defer resp.Body.Close() var p *Papertrail if err := decodeBodyMap(resp.Body, &p); err != nil { @@ -230,6 +234,7 @@ func (c *Client) DeletePapertrail(i *DeletePapertrailInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/platform_tls.go b/fastly/platform_tls.go index 29875c993..72577ee00 100644 --- a/fastly/platform_tls.go +++ b/fastly/platform_tls.go @@ -70,7 +70,6 @@ func (i *ListBulkCertificatesInput) formatFilters() map[string]string { // ListBulkCertificates list all certificates. func (c *Client) ListBulkCertificates(i *ListBulkCertificatesInput) ([]*BulkCertificate, error) { - p := "/tls/bulk/certificates" filters := &RequestOptions{ Params: i.formatFilters(), @@ -83,6 +82,7 @@ func (c *Client) ListBulkCertificates(i *ListBulkCertificatesInput) ([]*BulkCert if err != nil { return nil, err } + defer r.Body.Close() data, err := jsonapi.UnmarshalManyPayload(r.Body, reflect.TypeOf(new(BulkCertificate))) if err != nil { @@ -108,7 +108,6 @@ type GetBulkCertificateInput struct { // GetBulkCertificate retrieve a single certificate. func (c *Client) GetBulkCertificate(i *GetBulkCertificateInput) (*BulkCertificate, error) { - if i.ID == "" { return nil, ErrMissingID } @@ -119,6 +118,7 @@ func (c *Client) GetBulkCertificate(i *GetBulkCertificateInput) (*BulkCertificat if err != nil { return nil, err } + defer r.Body.Close() var bc BulkCertificate if err := jsonapi.UnmarshalPayload(r.Body, &bc); err != nil { @@ -138,7 +138,6 @@ type CreateBulkCertificateInput struct { // CreateBulkCertificate create a TLS private key. func (c *Client) CreateBulkCertificate(i *CreateBulkCertificateInput) (*BulkCertificate, error) { - if i.CertBlob == "" { return nil, ErrMissingCertBlob } @@ -152,6 +151,7 @@ func (c *Client) CreateBulkCertificate(i *CreateBulkCertificateInput) (*BulkCert if err != nil { return nil, err } + defer r.Body.Close() var bc BulkCertificate if err := jsonapi.UnmarshalPayload(r.Body, &bc); err != nil { @@ -191,6 +191,7 @@ func (c *Client) UpdateBulkCertificate(i *UpdateBulkCertificateInput) (*BulkCert if err != nil { return nil, err } + defer resp.Body.Close() var bc BulkCertificate if err := jsonapi.UnmarshalPayload(resp.Body, &bc); err != nil { diff --git a/fastly/pool.go b/fastly/pool.go index ad059cb69..1cd845b59 100644 --- a/fastly/pool.go +++ b/fastly/pool.go @@ -93,6 +93,7 @@ func (c *Client) ListPools(i *ListPoolsInput) ([]*Pool, error) { if err != nil { return nil, err } + defer resp.Body.Close() var ps []*Pool if err := decodeBodyMap(resp.Body, &ps); err != nil { @@ -155,6 +156,7 @@ func (c *Client) CreatePool(i *CreatePoolInput) (*Pool, error) { if err != nil { return nil, err } + defer resp.Body.Close() var p *Pool if err := decodeBodyMap(resp.Body, &p); err != nil { @@ -194,6 +196,7 @@ func (c *Client) GetPool(i *GetPoolInput) (*Pool, error) { if err != nil { return nil, err } + defer resp.Body.Close() var p *Pool if err := decodeBodyMap(resp.Body, &p); err != nil { @@ -256,6 +259,7 @@ func (c *Client) UpdatePool(i *UpdatePoolInput) (*Pool, error) { if err != nil { return nil, err } + defer resp.Body.Close() var p *Pool if err := decodeBodyMap(resp.Body, &p); err != nil { @@ -279,7 +283,6 @@ type DeletePoolInput struct { // DeletePool deletes a specific pool for a particular service and version. func (c *Client) DeletePool(i *DeletePoolInput) error { if i.ServiceID == "" { - return ErrMissingServiceID } @@ -296,6 +299,7 @@ func (c *Client) DeletePool(i *DeletePoolInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/pubsub.go b/fastly/pubsub.go index 7247d8ecd..e0fc583dc 100644 --- a/fastly/pubsub.go +++ b/fastly/pubsub.go @@ -60,6 +60,7 @@ func (c *Client) ListPubsubs(i *ListPubsubsInput) ([]*Pubsub, error) { if err != nil { return nil, err } + defer resp.Body.Close() var pubsubs []*Pubsub if err := decodeBodyMap(resp.Body, &pubsubs); err != nil { @@ -103,6 +104,7 @@ func (c *Client) CreatePubsub(i *CreatePubsubInput) (*Pubsub, error) { if err != nil { return nil, err } + defer resp.Body.Close() var pubsub *Pubsub if err := decodeBodyMap(resp.Body, &pubsub); err != nil { @@ -142,6 +144,7 @@ func (c *Client) GetPubsub(i *GetPubsubInput) (*Pubsub, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *Pubsub if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -191,6 +194,7 @@ func (c *Client) UpdatePubsub(i *UpdatePubsubInput) (*Pubsub, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *Pubsub if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -230,6 +234,7 @@ func (c *Client) DeletePubsub(i *DeletePubsubInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/purge.go b/fastly/purge.go index c5bcb2ced..cf9f327bc 100644 --- a/fastly/purge.go +++ b/fastly/purge.go @@ -49,6 +49,7 @@ func (c *Client) Purge(i *PurgeInput) (*Purge, error) { if err != nil { return nil, err } + defer resp.Body.Close() var r *Purge if err := decodeBodyMap(resp.Body, &r); err != nil { @@ -114,6 +115,7 @@ func (c *Client) PurgeKey(i *PurgeKeyInput) (*Purge, error) { if err != nil { return nil, err } + defer resp.Body.Close() var r *Purge if err := decodeBodyMap(resp.Body, &r); err != nil { @@ -163,6 +165,7 @@ func (c *Client) PurgeKeys(i *PurgeKeysInput) (map[string]string, error) { if err != nil { return nil, err } + defer resp.Body.Close() var r map[string]string if err := decodeBodyMap(resp.Body, &r); err != nil { @@ -193,6 +196,7 @@ func (c *Client) PurgeAll(i *PurgeAllInput) (*Purge, error) { if err != nil { return nil, err } + defer resp.Body.Close() var r *Purge if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/request_setting.go b/fastly/request_setting.go index c78fb737d..c43c2775a 100644 --- a/fastly/request_setting.go +++ b/fastly/request_setting.go @@ -97,6 +97,7 @@ func (c *Client) ListRequestSettings(i *ListRequestSettingsInput) ([]*RequestSet if err != nil { return nil, err } + defer resp.Body.Close() var bs []*RequestSetting if err := decodeBodyMap(resp.Body, &bs); err != nil { @@ -144,6 +145,7 @@ func (c *Client) CreateRequestSetting(i *CreateRequestSettingInput) (*RequestSet if err != nil { return nil, err } + defer resp.Body.Close() var b *RequestSetting if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -184,6 +186,7 @@ func (c *Client) GetRequestSetting(i *GetRequestSettingInput) (*RequestSetting, if err != nil { return nil, err } + defer resp.Body.Close() var b *RequestSetting if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -237,6 +240,7 @@ func (c *Client) UpdateRequestSetting(i *UpdateRequestSettingInput) (*RequestSet if err != nil { return nil, err } + defer resp.Body.Close() var b *RequestSetting if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -276,6 +280,7 @@ func (c *Client) DeleteRequestSetting(i *DeleteRequestSettingInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/response_object.go b/fastly/response_object.go index 57f6b0566..9d1279c0b 100644 --- a/fastly/response_object.go +++ b/fastly/response_object.go @@ -60,6 +60,7 @@ func (c *Client) ListResponseObjects(i *ListResponseObjectsInput) ([]*ResponseOb if err != nil { return nil, err } + defer resp.Body.Close() var bs []*ResponseObject if err := decodeBodyMap(resp.Body, &bs); err != nil { @@ -102,6 +103,7 @@ func (c *Client) CreateResponseObject(i *CreateResponseObjectInput) (*ResponseOb if err != nil { return nil, err } + defer resp.Body.Close() var b *ResponseObject if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -142,6 +144,7 @@ func (c *Client) GetResponseObject(i *GetResponseObjectInput) (*ResponseObject, if err != nil { return nil, err } + defer resp.Body.Close() var b *ResponseObject if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -190,6 +193,7 @@ func (c *Client) UpdateResponseObject(i *UpdateResponseObjectInput) (*ResponseOb if err != nil { return nil, err } + defer resp.Body.Close() var b *ResponseObject if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -229,6 +233,7 @@ func (c *Client) DeleteResponseObject(i *DeleteResponseObjectInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/s3.go b/fastly/s3.go index c0a92e325..c246a315b 100644 --- a/fastly/s3.go +++ b/fastly/s3.go @@ -106,6 +106,7 @@ func (c *Client) ListS3s(i *ListS3sInput) ([]*S3, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s3s []*S3 if err := decodeBodyMap(resp.Body, &s3s); err != nil { @@ -165,6 +166,7 @@ func (c *Client) CreateS3(i *CreateS3Input) (*S3, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s3 *S3 if err := decodeBodyMap(resp.Body, &s3); err != nil { @@ -204,6 +206,7 @@ func (c *Client) GetS3(i *GetS3Input) (*S3, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s3 *S3 if err := decodeBodyMap(resp.Body, &s3); err != nil { @@ -269,6 +272,7 @@ func (c *Client) UpdateS3(i *UpdateS3Input) (*S3, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s3 *S3 if err := decodeBodyMap(resp.Body, &s3); err != nil { @@ -308,6 +312,7 @@ func (c *Client) DeleteS3(i *DeleteS3Input) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/scalyr.go b/fastly/scalyr.go index e717ac125..867cf1ca4 100644 --- a/fastly/scalyr.go +++ b/fastly/scalyr.go @@ -58,6 +58,7 @@ func (c *Client) ListScalyrs(i *ListScalyrsInput) ([]*Scalyr, error) { if err != nil { return nil, err } + defer resp.Body.Close() var ss []*Scalyr if err := decodeBodyMap(resp.Body, &ss); err != nil { @@ -103,6 +104,7 @@ func (c *Client) CreateScalyr(i *CreateScalyrInput) (*Scalyr, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Scalyr if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -142,6 +144,7 @@ func (c *Client) GetScalyr(i *GetScalyrInput) (*Scalyr, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Scalyr if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -193,6 +196,7 @@ func (c *Client) UpdateScalyr(i *UpdateScalyrInput) (*Scalyr, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Scalyr if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -232,6 +236,7 @@ func (c *Client) DeleteScalyr(i *DeleteScalyrInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/server.go b/fastly/server.go index 6beafc644..0c4463729 100644 --- a/fastly/server.go +++ b/fastly/server.go @@ -58,6 +58,7 @@ func (c *Client) ListServers(i *ListServersInput) ([]*Server, error) { if err != nil { return nil, err } + defer resp.Body.Close() var ss []*Server if err := decodeBodyMap(resp.Body, &ss); err != nil { @@ -107,6 +108,7 @@ func (c *Client) CreateServer(i *CreateServerInput) (*Server, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Server if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -145,6 +147,7 @@ func (c *Client) GetServer(i *GetServerInput) (*Server, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Server if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -192,6 +195,7 @@ func (c *Client) UpdateServer(i *UpdateServerInput) (*Server, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Server if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -230,6 +234,7 @@ func (c *Client) DeleteServer(i *DeleteServerInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/service.go b/fastly/service.go index d227ec3d2..e62091214 100644 --- a/fastly/service.go +++ b/fastly/service.go @@ -74,6 +74,7 @@ func (c *Client) ListServices(i *ListServicesInput) ([]*Service, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s []*Service if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -158,6 +159,7 @@ func (c *Client) listServicesWithPage(i *ListServicesInput, p *ListServicesPagin if err != nil { return nil, err } + defer resp.Body.Close() for _, l := range link.ParseResponse(resp) { // indicates the Link response header contained the next page instruction @@ -199,6 +201,7 @@ func (c *Client) CreateService(i *CreateServiceInput) (*Service, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Service if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -225,6 +228,7 @@ func (c *Client) GetService(i *GetServiceInput) (*Service, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Service if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -258,6 +262,7 @@ func (c *Client) GetServiceDetails(i *GetServiceInput) (*ServiceDetail, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *ServiceDetail if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -294,6 +299,7 @@ func (c *Client) UpdateService(i *UpdateServiceInput) (*Service, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Service if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -318,6 +324,7 @@ func (c *Client) DeleteService(i *DeleteServiceInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { @@ -349,6 +356,7 @@ func (c *Client) SearchService(i *SearchServiceInput) (*Service, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Service if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -372,6 +380,7 @@ func (c *Client) ListServiceDomains(i *ListServiceDomainInput) (ServiceDomainsLi if err != nil { return nil, err } + defer resp.Body.Close() var ds ServiceDomainsList diff --git a/fastly/service_authorization.go b/fastly/service_authorization.go index 7b35f70f8..c075723c2 100644 --- a/fastly/service_authorization.go +++ b/fastly/service_authorization.go @@ -75,6 +75,7 @@ func (c *Client) ListServiceAuthorizations(i *ListServiceAuthorizationsInput) (* if err != nil { return nil, err } + defer resp.Body.Close() var buf bytes.Buffer tee := io.TeeReader(resp.Body, &buf) @@ -120,6 +121,7 @@ func (c *Client) GetServiceAuthorization(i *GetServiceAuthorizationInput) (*Serv if err != nil { return nil, err } + defer resp.Body.Close() var sa ServiceAuthorization if err := jsonapi.UnmarshalPayload(resp.Body, &sa); err != nil { @@ -157,6 +159,7 @@ func (c *Client) CreateServiceAuthorization(i *CreateServiceAuthorizationInput) if err != nil { return nil, err } + defer resp.Body.Close() var sa ServiceAuthorization if err := jsonapi.UnmarshalPayload(resp.Body, &sa); err != nil { @@ -190,6 +193,7 @@ func (c *Client) UpdateServiceAuthorization(i *UpdateServiceAuthorizationInput) if err != nil { return nil, err } + defer resp.Body.Close() var sa ServiceAuthorization if err := jsonapi.UnmarshalPayload(resp.Body, &sa); err != nil { diff --git a/fastly/settings.go b/fastly/settings.go index 5bc109c9e..c35baf315 100644 --- a/fastly/settings.go +++ b/fastly/settings.go @@ -37,6 +37,7 @@ func (c *Client) GetSettings(i *GetSettingsInput) (*Settings, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *Settings if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -74,6 +75,7 @@ func (c *Client) UpdateSettings(i *UpdateSettingsInput) (*Settings, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *Settings if err := decodeBodyMap(resp.Body, &b); err != nil { diff --git a/fastly/sftp.go b/fastly/sftp.go index a63ba7037..556e0a004 100644 --- a/fastly/sftp.go +++ b/fastly/sftp.go @@ -69,6 +69,7 @@ func (c *Client) ListSFTPs(i *ListSFTPsInput) ([]*SFTP, error) { if err != nil { return nil, err } + defer resp.Body.Close() var sftps []*SFTP if err := decodeBodyMap(resp.Body, &sftps); err != nil { @@ -121,6 +122,7 @@ func (c *Client) CreateSFTP(i *CreateSFTPInput) (*SFTP, error) { if err != nil { return nil, err } + defer resp.Body.Close() var ftp *SFTP if err := decodeBodyMap(resp.Body, &ftp); err != nil { @@ -160,6 +162,7 @@ func (c *Client) GetSFTP(i *GetSFTPInput) (*SFTP, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *SFTP if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -218,6 +221,7 @@ func (c *Client) UpdateSFTP(i *UpdateSFTPInput) (*SFTP, error) { if err != nil { return nil, err } + defer resp.Body.Close() var b *SFTP if err := decodeBodyMap(resp.Body, &b); err != nil { @@ -257,6 +261,7 @@ func (c *Client) DeleteSFTP(i *DeleteSFTPInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/splunk.go b/fastly/splunk.go index 58357d010..20b17abda 100644 --- a/fastly/splunk.go +++ b/fastly/splunk.go @@ -65,6 +65,7 @@ func (c *Client) ListSplunks(i *ListSplunksInput) ([]*Splunk, error) { if err != nil { return nil, err } + defer resp.Body.Close() var ss []*Splunk if err := decodeBodyMap(resp.Body, &ss); err != nil { @@ -117,6 +118,7 @@ func (c *Client) CreateSplunk(i *CreateSplunkInput) (*Splunk, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Splunk if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -156,6 +158,7 @@ func (c *Client) GetSplunk(i *GetSplunkInput) (*Splunk, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Splunk if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -214,6 +217,7 @@ func (c *Client) UpdateSplunk(i *UpdateSplunkInput) (*Splunk, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Splunk if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -253,6 +257,7 @@ func (c *Client) DeleteSplunk(i *DeleteSplunkInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/stats.go b/fastly/stats.go index b866d7eca..2b630238f 100644 --- a/fastly/stats.go +++ b/fastly/stats.go @@ -214,6 +214,8 @@ func (c *Client) GetUsage(i *GetUsageInput) (*UsageResponse, error) { if err != nil { return nil, err } + defer r.Body.Close() + var sr *UsageResponse if err := decodeBodyMap(r.Body, &sr); err != nil { return nil, err @@ -250,6 +252,8 @@ func (c *Client) GetUsageByService(i *GetUsageInput) (*UsageByServiceResponse, e if err != nil { return nil, err } + defer r.Body.Close() + var sr *UsageByServiceResponse if err := decodeBodyMap(r.Body, &sr); err != nil { return nil, err @@ -272,6 +276,7 @@ func (c *Client) GetRegions() (*RegionsResponse, error) { if err != nil { return nil, err } + defer r.Body.Close() var rr *RegionsResponse if err := decodeBodyMap(r.Body, &rr); err != nil { diff --git a/fastly/sumologic.go b/fastly/sumologic.go index 38ed7e3cc..bab5e20c8 100644 --- a/fastly/sumologic.go +++ b/fastly/sumologic.go @@ -59,6 +59,7 @@ func (c *Client) ListSumologics(i *ListSumologicsInput) ([]*Sumologic, error) { if err != nil { return nil, err } + defer resp.Body.Close() var ss []*Sumologic if err := decodeBodyMap(resp.Body, &ss); err != nil { @@ -101,6 +102,7 @@ func (c *Client) CreateSumologic(i *CreateSumologicInput) (*Sumologic, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Sumologic if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -140,6 +142,7 @@ func (c *Client) GetSumologic(i *GetSumologicInput) (*Sumologic, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Sumologic if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -188,6 +191,7 @@ func (c *Client) UpdateSumologic(i *UpdateSumologicInput) (*Sumologic, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Sumologic if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -227,6 +231,7 @@ func (c *Client) DeleteSumologic(i *DeleteSumologicInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/syslog.go b/fastly/syslog.go index 8cdecd29c..896251cbf 100644 --- a/fastly/syslog.go +++ b/fastly/syslog.go @@ -67,6 +67,7 @@ func (c *Client) ListSyslogs(i *ListSyslogsInput) ([]*Syslog, error) { if err != nil { return nil, err } + defer resp.Body.Close() var ss []*Syslog if err := decodeBodyMap(resp.Body, &ss); err != nil { @@ -117,6 +118,7 @@ func (c *Client) CreateSyslog(i *CreateSyslogInput) (*Syslog, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Syslog if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -156,6 +158,7 @@ func (c *Client) GetSyslog(i *GetSyslogInput) (*Syslog, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Syslog if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -212,6 +215,7 @@ func (c *Client) UpdateSyslog(i *UpdateSyslogInput) (*Syslog, error) { if err != nil { return nil, err } + defer resp.Body.Close() var s *Syslog if err := decodeBodyMap(resp.Body, &s); err != nil { @@ -251,6 +255,7 @@ func (c *Client) DeleteSyslog(i *DeleteSyslogInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/tls.go b/fastly/tls.go index a8bc83265..2242ad113 100644 --- a/fastly/tls.go +++ b/fastly/tls.go @@ -59,7 +59,6 @@ func (i *ListPrivateKeysInput) formatFilters() map[string]string { // ListPrivateKeys list all TLS private keys. func (c *Client) ListPrivateKeys(i *ListPrivateKeysInput) ([]*PrivateKey, error) { - p := "/tls/private_keys" filters := &RequestOptions{ Params: i.formatFilters(), @@ -72,6 +71,7 @@ func (c *Client) ListPrivateKeys(i *ListPrivateKeysInput) ([]*PrivateKey, error) if err != nil { return nil, err } + defer r.Body.Close() data, err := jsonapi.UnmarshalManyPayload(r.Body, reflect.TypeOf(new(PrivateKey))) if err != nil { @@ -92,7 +92,6 @@ func (c *Client) ListPrivateKeys(i *ListPrivateKeysInput) ([]*PrivateKey, error) // GetPrivateKey show a TLS private key. func (c *Client) GetPrivateKey(i *GetPrivateKeyInput) (*PrivateKey, error) { - if i.ID == "" { return nil, ErrMissingID } @@ -120,7 +119,6 @@ type CreatePrivateKeyInput struct { // CreatePrivateKey create a TLS private key. func (c *Client) CreatePrivateKey(i *CreatePrivateKeyInput) (*PrivateKey, error) { - p := "/tls/private_keys" if i.Key == "" { diff --git a/fastly/tls_subscription.go b/fastly/tls_subscription.go index 47ea4c422..a576c7fa5 100644 --- a/fastly/tls_subscription.go +++ b/fastly/tls_subscription.go @@ -104,7 +104,7 @@ func (s *ListTLSSubscriptionsInput) formatFilters() map[string]string { // ListTLSSubscriptions lists all managed TLS subscriptions func (c *Client) ListTLSSubscriptions(i *ListTLSSubscriptionsInput) ([]*TLSSubscription, error) { - response, err := c.Get("/tls/subscriptions", &RequestOptions{ + resp, err := c.Get("/tls/subscriptions", &RequestOptions{ Params: i.formatFilters(), Headers: map[string]string{ "Accept": "application/vnd.api+json", // Needed for "include" but seemingly not the other fields @@ -113,8 +113,9 @@ func (c *Client) ListTLSSubscriptions(i *ListTLSSubscriptionsInput) ([]*TLSSubsc if err != nil { return nil, err } + defer resp.Body.Close() - data, err := jsonapi.UnmarshalManyPayload(response.Body, reflect.TypeOf(new(TLSSubscription))) + data, err := jsonapi.UnmarshalManyPayload(resp.Body, reflect.TypeOf(new(TLSSubscription))) if err != nil { return nil, err } @@ -154,13 +155,14 @@ func (c *Client) CreateTLSSubscription(i *CreateTLSSubscriptionInput) (*TLSSubsc return nil, ErrCommonNameNotInDomains } - response, err := c.PostJSONAPI("/tls/subscriptions", i, nil) + resp, err := c.PostJSONAPI("/tls/subscriptions", i, nil) if err != nil { return nil, err } + defer resp.Body.Close() var subscription TLSSubscription - err = jsonapi.UnmarshalPayload(response.Body, &subscription) + err = jsonapi.UnmarshalPayload(resp.Body, &subscription) if err != nil { return nil, err } @@ -205,13 +207,14 @@ func (c *Client) GetTLSSubscription(i *GetTLSSubscriptionInput) (*TLSSubscriptio requestOptions.Params = map[string]string{"include": *i.Include} } - response, err := c.Get(path, requestOptions) + resp, err := c.Get(path, requestOptions) if err != nil { return nil, err } + defer resp.Body.Close() var subscription TLSSubscription - err = jsonapi.UnmarshalPayload(response.Body, &subscription) + err = jsonapi.UnmarshalPayload(resp.Body, &subscription) if err != nil { return nil, err } @@ -248,13 +251,14 @@ func (c *Client) UpdateTLSSubscription(i *UpdateTLSSubscriptionInput) (*TLSSubsc } path := fmt.Sprintf("/tls/subscriptions/%s", i.ID) - response, err := c.PatchJSONAPI(path, i, &ro) + resp, err := c.PatchJSONAPI(path, i, &ro) if err != nil { return nil, err } + defer resp.Body.Close() var subscription TLSSubscription - err = jsonapi.UnmarshalPayload(response.Body, &subscription) + err = jsonapi.UnmarshalPayload(resp.Body, &subscription) if err != nil { return nil, err } diff --git a/fastly/token.go b/fastly/token.go index e88103417..a8fd8fccd 100644 --- a/fastly/token.go +++ b/fastly/token.go @@ -53,6 +53,7 @@ func (c *Client) ListTokens() ([]*Token, error) { if err != nil { return nil, err } + defer resp.Body.Close() var t []*Token if err := decodeBodyMap(resp.Body, &t); err != nil { @@ -79,6 +80,7 @@ func (c *Client) ListCustomerTokens(i *ListCustomerTokensInput) ([]*Token, error if err != nil { return nil, err } + defer resp.Body.Close() var t []*Token if err := decodeBodyMap(resp.Body, &t); err != nil { @@ -96,6 +98,7 @@ func (c *Client) GetTokenSelf() (*Token, error) { if err != nil { return nil, err } + defer resp.Body.Close() var t *Token if err := decodeBodyMap(resp.Body, &t); err != nil { @@ -126,6 +129,7 @@ func (c *Client) CreateToken(i *CreateTokenInput) (*Token, error) { if err != nil { return nil, err } + defer resp.Body.Close() var t *Token if err := decodeBodyMap(resp.Body, &t); err != nil { @@ -150,6 +154,7 @@ func (c *Client) DeleteToken(i *DeleteTokenInput) error { if err != nil { return err } + defer resp.Body.Close() if resp.StatusCode != http.StatusNoContent { return ErrNotOK @@ -163,6 +168,7 @@ func (c *Client) DeleteTokenSelf() error { if err != nil { return err } + defer resp.Body.Close() if resp.StatusCode != http.StatusNoContent { return ErrNotOK diff --git a/fastly/user.go b/fastly/user.go index f86e297ed..a1534904d 100644 --- a/fastly/user.go +++ b/fastly/user.go @@ -52,6 +52,7 @@ func (c *Client) ListCustomerUsers(i *ListCustomerUsersInput) ([]*User, error) { if err != nil { return nil, err } + defer resp.Body.Close() var u []*User if err := decodeBodyMap(resp.Body, &u); err != nil { @@ -67,6 +68,7 @@ func (c *Client) GetCurrentUser() (*User, error) { if err != nil { return nil, err } + defer resp.Body.Close() var u *User if err := decodeBodyMap(resp.Body, &u); err != nil { @@ -93,6 +95,7 @@ func (c *Client) GetUser(i *GetUserInput) (*User, error) { if err != nil { return nil, err } + defer resp.Body.Close() var u *User if err := decodeBodyMap(resp.Body, &u); err != nil { @@ -124,6 +127,7 @@ func (c *Client) CreateUser(i *CreateUserInput) (*User, error) { if err != nil { return nil, err } + defer resp.Body.Close() var u *User if err := decodeBodyMap(resp.Body, &u); err != nil { @@ -151,6 +155,7 @@ func (c *Client) UpdateUser(i *UpdateUserInput) (*User, error) { if err != nil { return nil, err } + defer resp.Body.Close() var u *User if err := decodeBodyMap(resp.Body, &u); err != nil { @@ -175,6 +180,7 @@ func (c *Client) DeleteUser(i *DeleteUserInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { @@ -202,6 +208,7 @@ func (c *Client) ResetUserPassword(i *ResetUserPasswordInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/vcl.go b/fastly/vcl.go index b195cca3b..675e620d0 100644 --- a/fastly/vcl.go +++ b/fastly/vcl.go @@ -54,6 +54,7 @@ func (c *Client) ListVCLs(i *ListVCLsInput) ([]*VCL, error) { if err != nil { return nil, err } + defer resp.Body.Close() var vcls []*VCL if err := decodeBodyMap(resp.Body, &vcls); err != nil { @@ -94,6 +95,7 @@ func (c *Client) GetVCL(i *GetVCLInput) (*VCL, error) { if err != nil { return nil, err } + defer resp.Body.Close() var vcl *VCL if err := decodeBodyMap(resp.Body, &vcl); err != nil { @@ -126,6 +128,7 @@ func (c *Client) GetGeneratedVCL(i *GetGeneratedVCLInput) (*VCL, error) { if err != nil { return nil, err } + defer resp.Body.Close() var vcl *VCL if err := decodeBodyMap(resp.Body, &vcl); err != nil { @@ -162,6 +165,7 @@ func (c *Client) CreateVCL(i *CreateVCLInput) (*VCL, error) { if err != nil { return nil, err } + defer resp.Body.Close() var vcl *VCL if err := decodeBodyMap(resp.Body, &vcl); err != nil { @@ -204,6 +208,7 @@ func (c *Client) UpdateVCL(i *UpdateVCLInput) (*VCL, error) { if err != nil { return nil, err } + defer resp.Body.Close() var vcl *VCL if err := decodeBodyMap(resp.Body, &vcl); err != nil { @@ -243,6 +248,7 @@ func (c *Client) ActivateVCL(i *ActivateVCLInput) (*VCL, error) { if err != nil { return nil, err } + defer resp.Body.Close() var vcl *VCL if err := decodeBodyMap(resp.Body, &vcl); err != nil { @@ -282,6 +288,7 @@ func (c *Client) DeleteVCL(i *DeleteVCLInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { diff --git a/fastly/vcl_snippets.go b/fastly/vcl_snippets.go index 48c31a11a..e2bdac042 100644 --- a/fastly/vcl_snippets.go +++ b/fastly/vcl_snippets.go @@ -120,6 +120,7 @@ func (c *Client) CreateSnippet(i *CreateSnippetInput) (*Snippet, error) { if err != nil { return nil, err } + defer resp.Body.Close() var snippet *Snippet if err := decodeBodyMap(resp.Body, &snippet); err != nil { @@ -170,6 +171,7 @@ func (c *Client) UpdateSnippet(i *UpdateSnippetInput) (*Snippet, error) { if err != nil { return nil, err } + defer resp.Body.Close() var snippet *Snippet if err := decodeBodyMap(resp.Body, &snippet); err != nil { @@ -215,6 +217,7 @@ func (c *Client) UpdateDynamicSnippet(i *UpdateDynamicSnippetInput) (*DynamicSni if err != nil { return nil, err } + defer resp.Body.Close() var updateSnippet *DynamicSnippet if err := decodeBodyMap(resp.Body, &updateSnippet); err != nil { @@ -252,6 +255,7 @@ func (c *Client) DeleteSnippet(i *DeleteSnippetInput) error { if err != nil { return err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { @@ -298,6 +302,7 @@ func (c *Client) ListSnippets(i *ListSnippetsInput) ([]*Snippet, error) { if err != nil { return nil, err } + defer resp.Body.Close() var snippets []*Snippet if err := decodeBodyMap(resp.Body, &snippets); err != nil { @@ -339,6 +344,7 @@ func (c *Client) GetSnippet(i *GetSnippetInput) (*Snippet, error) { if err != nil { return nil, err } + defer resp.Body.Close() var snippet *Snippet if err := decodeBodyMap(resp.Body, &snippet); err != nil { @@ -372,6 +378,7 @@ func (c *Client) GetDynamicSnippet(i *GetDynamicSnippetInput) (*DynamicSnippet, if err != nil { return nil, err } + defer resp.Body.Close() var snippet *DynamicSnippet if err := decodeBodyMap(resp.Body, &snippet); err != nil { diff --git a/fastly/version.go b/fastly/version.go index ce6fc14d3..845143887 100644 --- a/fastly/version.go +++ b/fastly/version.go @@ -49,6 +49,7 @@ func (c *Client) ListVersions(i *ListVersionsInput) ([]*Version, error) { if err != nil { return nil, err } + defer resp.Body.Close() var e []*Version if err := decodeBodyMap(resp.Body, &e); err != nil { @@ -106,6 +107,7 @@ func (c *Client) CreateVersion(i *CreateVersionInput) (*Version, error) { if err != nil { return nil, err } + defer resp.Body.Close() var e *Version if err := decodeBodyMap(resp.Body, &e); err != nil { @@ -138,6 +140,7 @@ func (c *Client) GetVersion(i *GetVersionInput) (*Version, error) { if err != nil { return nil, err } + defer resp.Body.Close() var e *Version if err := decodeBodyMap(resp.Body, &e); err != nil { @@ -173,6 +176,7 @@ func (c *Client) UpdateVersion(i *UpdateVersionInput) (*Version, error) { if err != nil { return nil, err } + defer resp.Body.Close() var e *Version if err := decodeBodyMap(resp.Body, &e); err != nil { @@ -205,6 +209,7 @@ func (c *Client) ActivateVersion(i *ActivateVersionInput) (*Version, error) { if err != nil { return nil, err } + defer resp.Body.Close() var e *Version if err := decodeBodyMap(resp.Body, &e); err != nil { @@ -237,6 +242,7 @@ func (c *Client) DeactivateVersion(i *DeactivateVersionInput) (*Version, error) if err != nil { return nil, err } + defer resp.Body.Close() var e *Version if err := decodeBodyMap(resp.Body, &e); err != nil { @@ -271,6 +277,7 @@ func (c *Client) CloneVersion(i *CloneVersionInput) (*Version, error) { if err != nil { return nil, err } + defer resp.Body.Close() var e *Version if err := decodeBodyMap(resp.Body, &e); err != nil { @@ -305,6 +312,7 @@ func (c *Client) ValidateVersion(i *ValidateVersionInput) (bool, string, error) if err != nil { return false, msg, err } + defer resp.Body.Close() var r *statusResp if err := decodeBodyMap(resp.Body, &r); err != nil { @@ -339,6 +347,7 @@ func (c *Client) LockVersion(i *LockVersionInput) (*Version, error) { if err != nil { return nil, err } + defer resp.Body.Close() var e *Version if err := decodeBodyMap(resp.Body, &e); err != nil { diff --git a/fastly/waf.go b/fastly/waf.go index 228c219f1..32c934941 100644 --- a/fastly/waf.go +++ b/fastly/waf.go @@ -61,7 +61,6 @@ type ListWAFsInput struct { } func (i *ListWAFsInput) formatFilters() map[string]string { - result := map[string]string{} pairings := map[string]interface{}{ "page[size]": i.PageSize, @@ -88,13 +87,13 @@ func (i *ListWAFsInput) formatFilters() map[string]string { // ListWAFs returns the list of wafs for the configuration version. func (c *Client) ListWAFs(i *ListWAFsInput) (*WAFResponse, error) { - resp, err := c.Get("/waf/firewalls", &RequestOptions{ Params: i.formatFilters(), }) if err != nil { return nil, err } + defer resp.Body.Close() var buf bytes.Buffer tee := io.TeeReader(resp.Body, &buf) @@ -151,6 +150,7 @@ func (c *Client) CreateWAF(i *CreateWAFInput) (*WAF, error) { if err != nil { return nil, err } + defer resp.Body.Close() var waf WAF if err := jsonapi.UnmarshalPayload(resp.Body, &waf); err != nil { @@ -194,6 +194,7 @@ func (c *Client) GetWAF(i *GetWAFInput) (*WAF, error) { if err != nil { return nil, err } + defer resp.Body.Close() var waf WAF if err := jsonapi.UnmarshalPayload(resp.Body, &waf); err != nil { @@ -240,6 +241,7 @@ func (c *Client) UpdateWAF(i *UpdateWAFInput) (*WAF, error) { if err != nil { return nil, err } + defer resp.Body.Close() var waf WAF if err := jsonapi.UnmarshalPayload(resp.Body, &waf); err != nil { @@ -258,7 +260,6 @@ type DeleteWAFInput struct { // DeleteWAF deletes a given WAF from its service. func (c *Client) DeleteWAF(i *DeleteWAFInput) error { - if i.ServiceVersion == 0 { return ErrMissingServiceVersion } @@ -296,7 +297,6 @@ type metaInfo struct { // getResponseInfo parses a response to get the pagination and metadata info. func getResponseInfo(body io.Reader) (infoResponse, error) { - bodyBytes, err := io.ReadAll(body) if err != nil { return infoResponse{}, err diff --git a/fastly/waf_active_rule.go b/fastly/waf_active_rule.go index a6438c741..eee32d0c3 100644 --- a/fastly/waf_active_rule.go +++ b/fastly/waf_active_rule.go @@ -54,7 +54,6 @@ type ListWAFActiveRulesInput struct { } func (i *ListWAFActiveRulesInput) formatFilters() map[string]string { - result := map[string]string{} pairings := map[string]interface{}{ "filter[status]": i.FilterStatus, @@ -82,7 +81,6 @@ func (i *ListWAFActiveRulesInput) formatFilters() map[string]string { // ListWAFActiveRules returns the list of active rules for a given WAF ID. func (c *Client) ListWAFActiveRules(i *ListWAFActiveRulesInput) (*WAFActiveRuleResponse, error) { - if i.WAFID == "" { return nil, ErrMissingWAFID } @@ -98,6 +96,7 @@ func (c *Client) ListWAFActiveRules(i *ListWAFActiveRulesInput) (*WAFActiveRuleR if err != nil { return nil, err } + defer resp.Body.Close() var buf bytes.Buffer tee := io.TeeReader(resp.Body, &buf) @@ -145,7 +144,6 @@ type ListAllWAFActiveRulesInput struct { // ListAllWAFActiveRules returns the complete list of WAF active rules for a given WAF ID. It iterates through // all existing pages to ensure all WAF active rules are returned at once. func (c *Client) ListAllWAFActiveRules(i *ListAllWAFActiveRulesInput) (*WAFActiveRuleResponse, error) { - if i.WAFID == "" { return nil, ErrMissingWAFID } @@ -192,7 +190,6 @@ type CreateWAFActiveRulesInput struct { // CreateWAFActiveRules adds rules to a particular WAF. func (c *Client) CreateWAFActiveRules(i *CreateWAFActiveRulesInput) ([]*WAFActiveRule, error) { - if i.WAFID == "" { return nil, ErrMissingWAFID } @@ -210,6 +207,7 @@ func (c *Client) CreateWAFActiveRules(i *CreateWAFActiveRulesInput) ([]*WAFActiv if err != nil { return nil, err } + defer resp.Body.Close() data, err := jsonapi.UnmarshalManyPayload(resp.Body, WAFActiveRuleType) if err != nil { @@ -243,7 +241,6 @@ type BatchModificationWAFActiveRulesInput struct { // BatchModificationWAFActiveRules is a generic function for creating or deleting WAF active rules in batches. // Upsert and delete are the only operations allowed. func (c *Client) BatchModificationWAFActiveRules(i *BatchModificationWAFActiveRulesInput) ([]*WAFActiveRule, error) { - if len(i.Rules) > BatchModifyMaximumOperations { return nil, ErrMaxExceededRules } @@ -278,7 +275,6 @@ type DeleteWAFActiveRulesInput struct { // DeleteWAFActiveRules removes rules from a particular WAF. func (c *Client) DeleteWAFActiveRules(i *DeleteWAFActiveRulesInput) error { - if i.WAFID == "" { return ErrMissingWAFID } diff --git a/fastly/waf_rule_exclusion.go b/fastly/waf_rule_exclusion.go index 9253aaa68..e039cdfed 100644 --- a/fastly/waf_rule_exclusion.go +++ b/fastly/waf_rule_exclusion.go @@ -110,7 +110,6 @@ type DeleteWAFRuleExclusionInput struct { } func (i *ListWAFRuleExclusionsInput) formatFilters() map[string]string { - include := strings.Join(i.Include, ",") result := map[string]string{} @@ -144,7 +143,6 @@ func (i *ListWAFRuleExclusionsInput) formatFilters() map[string]string { // ListWAFRuleExclusions returns the list of exclusions for a given WAF ID. func (c *Client) ListWAFRuleExclusions(i *ListWAFRuleExclusionsInput) (*WAFRuleExclusionResponse, error) { - if i.WAFID == "" { return nil, ErrMissingWAFID } @@ -160,6 +158,7 @@ func (c *Client) ListWAFRuleExclusions(i *ListWAFRuleExclusionsInput) (*WAFRuleE if err != nil { return nil, err } + defer resp.Body.Close() var buf bytes.Buffer tee := io.TeeReader(resp.Body, &buf) @@ -191,7 +190,6 @@ func (c *Client) ListWAFRuleExclusions(i *ListWAFRuleExclusionsInput) (*WAFRuleE // ListAllWAFRuleExclusions returns the complete list of WAF rule exclusions for a given WAF ID. It iterates through // all existing pages to ensure all WAF rule exclusions are returned at once. func (c *Client) ListAllWAFRuleExclusions(i *ListAllWAFRuleExclusionsInput) (*WAFRuleExclusionResponse, error) { - if i.WAFID == "" { return nil, ErrMissingWAFID } @@ -229,7 +227,6 @@ func (c *Client) ListAllWAFRuleExclusions(i *ListAllWAFRuleExclusionsInput) (*WA // CreateWAFRuleExclusion used to create a particular WAF rule exclusion. func (c *Client) CreateWAFRuleExclusion(i *CreateWAFRuleExclusionInput) (*WAFRuleExclusion, error) { - if i.WAFID == "" { return nil, ErrMissingWAFID } @@ -247,6 +244,7 @@ func (c *Client) CreateWAFRuleExclusion(i *CreateWAFRuleExclusionInput) (*WAFRul if err != nil { return nil, err } + defer resp.Body.Close() var wafExclusion WAFRuleExclusion if err := jsonapi.UnmarshalPayload(resp.Body, &wafExclusion); err != nil { @@ -278,6 +276,7 @@ func (c *Client) UpdateWAFRuleExclusion(i *UpdateWAFRuleExclusionInput) (*WAFRul if err != nil { return nil, err } + defer resp.Body.Close() var exc *WAFRuleExclusion if err := decodeBodyMap(resp.Body, &exc); err != nil { diff --git a/fastly/waf_rules.go b/fastly/waf_rules.go index f3f46db54..da65302c2 100644 --- a/fastly/waf_rules.go +++ b/fastly/waf_rules.go @@ -63,7 +63,6 @@ type ListWAFRulesInput struct { } func (i *ListWAFRulesInput) formatFilters() map[string]string { - result := map[string]string{} pairings := map[string]interface{}{ "filter[waf_tags][name][in]": i.FilterTagNames, @@ -105,13 +104,13 @@ func (i *ListWAFRulesInput) formatFilters() map[string]string { // ListWAFRules returns the list of VAF versions for a given WAF ID. func (c *Client) ListWAFRules(i *ListWAFRulesInput) (*WAFRuleResponse, error) { - resp, err := c.Get("/waf/rules", &RequestOptions{ Params: i.formatFilters(), }) if err != nil { return nil, err } + defer resp.Body.Close() var buf bytes.Buffer tee := io.TeeReader(resp.Body, &buf) @@ -157,7 +156,6 @@ type ListAllWAFRulesInput struct { // ListAllWAFRules returns the complete list of WAF rules for the given filters. It iterates through // all existing pages to ensure all WAF rules are returned at once. func (c *Client) ListAllWAFRules(i *ListAllWAFRulesInput) (*WAFRuleResponse, error) { - currentPage := 1 result := &WAFRuleResponse{Items: []*WAFRule{}} for { diff --git a/fastly/waf_version.go b/fastly/waf_version.go index d22743a4b..122bb50c8 100644 --- a/fastly/waf_version.go +++ b/fastly/waf_version.go @@ -104,7 +104,6 @@ type ListWAFVersionsInput struct { } func (i *ListWAFVersionsInput) formatFilters() map[string]string { - result := map[string]string{} pairings := map[string]interface{}{ "page[size]": i.PageSize, @@ -129,7 +128,6 @@ func (i *ListWAFVersionsInput) formatFilters() map[string]string { // ListWAFVersions returns the list of VAF versions for a given WAF ID. func (c *Client) ListWAFVersions(i *ListWAFVersionsInput) (*WAFVersionResponse, error) { - if i.WAFID == "" { return nil, ErrMissingWAFID } @@ -141,6 +139,7 @@ func (c *Client) ListWAFVersions(i *ListWAFVersionsInput) (*WAFVersionResponse, if err != nil { return nil, err } + defer resp.Body.Close() var buf bytes.Buffer tee := io.TeeReader(resp.Body, &buf) @@ -180,7 +179,6 @@ type ListAllWAFVersionsInput struct { // ListAllWAFVersions returns the complete list of WAF versions for a given WAF ID. It iterates through // all existing pages to ensure all WAF versions are returned at once. func (c *Client) ListAllWAFVersions(i *ListAllWAFVersionsInput) (*WAFVersionResponse, error) { - if i.WAFID == "" { return nil, ErrMissingWAFID } @@ -217,7 +215,6 @@ type GetWAFVersionInput struct { // GetWAFVersion gets details for given WAF version. func (c *Client) GetWAFVersion(i *GetWAFVersionInput) (*WAFVersion, error) { - if i.WAFID == "" { return nil, ErrMissingWAFID } @@ -231,6 +228,7 @@ func (c *Client) GetWAFVersion(i *GetWAFVersionInput) (*WAFVersion, error) { if err != nil { return nil, err } + defer resp.Body.Close() var wafVer WAFVersion if err := jsonapi.UnmarshalPayload(resp.Body, &wafVer); err != nil { @@ -309,6 +307,7 @@ func (c *Client) UpdateWAFVersion(i *UpdateWAFVersionInput) (*WAFVersion, error) if err != nil { return nil, err } + defer resp.Body.Close() var waf WAFVersion if err := jsonapi.UnmarshalPayload(resp.Body, &waf); err != nil { @@ -342,6 +341,7 @@ func (c *Client) LockWAFVersion(i *LockWAFVersionInput) (*WAFVersion, error) { if err != nil { return nil, err } + defer resp.Body.Close() var waf WAFVersion if err := jsonapi.UnmarshalPayload(resp.Body, &waf); err != nil { @@ -373,6 +373,7 @@ func (c *Client) CloneWAFVersion(i *CloneWAFVersionInput) (*WAFVersion, error) { if err != nil { return nil, err } + defer resp.Body.Close() var waf WAFVersion if err := jsonapi.UnmarshalPayload(resp.Body, &waf); err != nil { @@ -391,7 +392,6 @@ type DeployWAFVersionInput struct { // DeployWAFVersion deploys a specific WAF version. func (c *Client) DeployWAFVersion(i *DeployWAFVersionInput) error { - if i.WAFID == "" { return ErrMissingWAFID } @@ -417,7 +417,6 @@ type CreateEmptyWAFVersionInput struct { // CreateEmptyWAFVersion creates an empty WAF version, // which means a version without rules and all config options set to their default values. func (c *Client) CreateEmptyWAFVersion(i *CreateEmptyWAFVersionInput) (*WAFVersion, error) { - if i.WAFID == "" { return nil, ErrMissingWAFID } @@ -427,6 +426,7 @@ func (c *Client) CreateEmptyWAFVersion(i *CreateEmptyWAFVersionInput) (*WAFVersi if err != nil { return nil, err } + defer resp.Body.Close() var waf WAFVersion if err := jsonapi.UnmarshalPayload(resp.Body, &waf); err != nil {