diff --git a/.changelog/1121.txt b/.changelog/1121.txt new file mode 100644 index 000000000..75e087cdf --- /dev/null +++ b/.changelog/1121.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +deps: fix import grouping, code formatting and enable goimports linter +``` diff --git a/.golintci.yaml b/.golintci.yaml index b2c62e408..c885d96e1 100644 --- a/.golintci.yaml +++ b/.golintci.yaml @@ -32,6 +32,7 @@ linters: - exportloopref # prevent scope issues with pointers in loops. - goconst # use constants where values are repeated. - reassign # checks that package variables are not reassigned. + - goimports # checks import grouping and code formatting. output: format: colored-line-number diff --git a/cmd/flarectl/firewall.go b/cmd/flarectl/firewall.go index 16d047d47..8003ee78f 100644 --- a/cmd/flarectl/firewall.go +++ b/cmd/flarectl/firewall.go @@ -2,13 +2,12 @@ package main import ( "context" + "errors" "fmt" "net" "os" "strconv" - "errors" - "github.com/cloudflare/cloudflare-go" "github.com/urfave/cli/v2" ) diff --git a/cmd/flarectl/misc.go b/cmd/flarectl/misc.go index 836dc2582..edad3d980 100644 --- a/cmd/flarectl/misc.go +++ b/cmd/flarectl/misc.go @@ -3,12 +3,11 @@ package main import ( "context" "encoding/json" + "errors" "fmt" "os" "strings" - "errors" - cloudflare "github.com/cloudflare/cloudflare-go" "github.com/olekukonko/tablewriter" "github.com/urfave/cli/v2" @@ -46,7 +45,7 @@ func initializeAPI(c *cli.Context) error { } if c.IsSet("account-id") { - cloudflare.UsingAccount(c.String("account-id"))(api) //nolint + cloudflare.UsingAccount(c.String("account-id"))(api) // nolint } return nil @@ -93,7 +92,7 @@ func writeTable(c *cli.Context, data [][]string, cols ...string) { func checkFlags(c *cli.Context, flags ...string) error { for _, flag := range flags { if c.String(flag) == "" { - cli.ShowSubcommandHelp(c) //nolint + cli.ShowSubcommandHelp(c) // nolint err := fmt.Errorf("error: the required flag %q was empty or not provided", flag) fmt.Fprintln(os.Stderr, err) return err diff --git a/convert_types.go b/convert_types.go index ef4600006..1d45d3455 100644 --- a/convert_types.go +++ b/convert_types.go @@ -22,26 +22,26 @@ import ( // AnyPtr is a helper routine that allocates a new interface value // to store v and returns a pointer to it. // -// // Usage: var _ *Type = AnyPtr(Type(value) | value).(*Type) +// Usage: var _ *Type = AnyPtr(Type(value) | value).(*Type) // -// var _ *bool = AnyPtr(true).(*bool) -// var _ *byte = AnyPtr(byte(1)).(*byte) -// var _ *complex64 = AnyPtr(complex64(1.1)).(*complex64) -// var _ *complex128 = AnyPtr(complex128(1.1)).(*complex128) -// var _ *float32 = AnyPtr(float32(1.1)).(*float32) -// var _ *float64 = AnyPtr(float64(1.1)).(*float64) -// var _ *int = AnyPtr(int(1)).(*int) -// var _ *int8 = AnyPtr(int8(8)).(*int8) -// var _ *int16 = AnyPtr(int16(16)).(*int16) -// var _ *int32 = AnyPtr(int32(32)).(*int32) -// var _ *int64 = AnyPtr(int64(64)).(*int64) -// var _ *rune = AnyPtr(rune(1)).(*rune) -// var _ *string = AnyPtr("ptr").(*string) -// var _ *uint = AnyPtr(uint(1)).(*uint) -// var _ *uint8 = AnyPtr(uint8(8)).(*uint8) -// var _ *uint16 = AnyPtr(uint16(16)).(*uint16) -// var _ *uint32 = AnyPtr(uint32(32)).(*uint32) -// var _ *uint64 = AnyPtr(uint64(64)).(*uint64) +// var _ *bool = AnyPtr(true).(*bool) +// var _ *byte = AnyPtr(byte(1)).(*byte) +// var _ *complex64 = AnyPtr(complex64(1.1)).(*complex64) +// var _ *complex128 = AnyPtr(complex128(1.1)).(*complex128) +// var _ *float32 = AnyPtr(float32(1.1)).(*float32) +// var _ *float64 = AnyPtr(float64(1.1)).(*float64) +// var _ *int = AnyPtr(int(1)).(*int) +// var _ *int8 = AnyPtr(int8(8)).(*int8) +// var _ *int16 = AnyPtr(int16(16)).(*int16) +// var _ *int32 = AnyPtr(int32(32)).(*int32) +// var _ *int64 = AnyPtr(int64(64)).(*int64) +// var _ *rune = AnyPtr(rune(1)).(*rune) +// var _ *string = AnyPtr("ptr").(*string) +// var _ *uint = AnyPtr(uint(1)).(*uint) +// var _ *uint8 = AnyPtr(uint8(8)).(*uint8) +// var _ *uint16 = AnyPtr(uint16(16)).(*uint16) +// var _ *uint32 = AnyPtr(uint32(32)).(*uint32) +// var _ *uint64 = AnyPtr(uint64(64)).(*uint64) func AnyPtr(v interface{}) interface{} { r := reflect.New(reflect.TypeOf(v)) reflect.ValueOf(r.Interface()).Elem().Set(reflect.ValueOf(v)) diff --git a/custom_hostname.go b/custom_hostname.go index fe1be31bc..29bbdb9fe 100644 --- a/custom_hostname.go +++ b/custom_hostname.go @@ -3,13 +3,12 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "net/url" "strconv" "time" - - "errors" ) // CustomHostnameStatus is the enumeration of valid state values in the CustomHostnameSSL. @@ -38,14 +37,14 @@ type CustomHostnameSSLSettings struct { EarlyHints string `json:"early_hints,omitempty"` } -//CustomHostnameOwnershipVerification represents ownership verification status of a given custom hostname. +// CustomHostnameOwnershipVerification represents ownership verification status of a given custom hostname. type CustomHostnameOwnershipVerification struct { Type string `json:"type,omitempty"` Name string `json:"name,omitempty"` Value string `json:"value,omitempty"` } -//SSLValidationError represents errors that occurred during SSL validation. +// SSLValidationError represents errors that occurred during SSL validation. type SSLValidationError struct { Message string `json:"message,omitempty"` } diff --git a/errors.go b/errors.go index 9b92d1dca..994707978 100644 --- a/errors.go +++ b/errors.go @@ -1,11 +1,10 @@ package cloudflare import ( + "errors" "fmt" "net/http" "strings" - - "errors" ) const ( diff --git a/filter.go b/filter.go index 532bf5617..904b6b055 100644 --- a/filter.go +++ b/filter.go @@ -3,11 +3,10 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "net/url" - - "errors" ) var ErrNotEnoughFilterIDsProvided = errors.New("at least one filter ID must be provided.") diff --git a/images.go b/images.go index 58d3e17e1..8cb9fd2f7 100644 --- a/images.go +++ b/images.go @@ -4,13 +4,12 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" "io" "mime/multipart" "net/http" "time" - - "errors" ) // Image represents a Cloudflare Image. diff --git a/intelligence_asn_test.go b/intelligence_asn_test.go index 6d20dc6f3..f66fffbe8 100644 --- a/intelligence_asn_test.go +++ b/intelligence_asn_test.go @@ -3,9 +3,10 @@ package cloudflare import ( "context" "fmt" - "github.com/stretchr/testify/assert" "net/http" "testing" + + "github.com/stretchr/testify/assert" ) const testASNNumber = "13335" diff --git a/intelligence_domain_test.go b/intelligence_domain_test.go index f6ef9e436..185502bdb 100644 --- a/intelligence_domain_test.go +++ b/intelligence_domain_test.go @@ -3,9 +3,10 @@ package cloudflare import ( "context" "fmt" - "github.com/stretchr/testify/assert" "net/http" "testing" + + "github.com/stretchr/testify/assert" ) func TestIntelligence_DomainDetails(t *testing.T) { diff --git a/intelligence_ip_test.go b/intelligence_ip_test.go index 829b867de..b8389fec5 100644 --- a/intelligence_ip_test.go +++ b/intelligence_ip_test.go @@ -3,9 +3,10 @@ package cloudflare import ( "context" "fmt" - "github.com/stretchr/testify/assert" "net/http" "testing" + + "github.com/stretchr/testify/assert" ) func TestIntelligence_GetIPOverview(t *testing.T) { diff --git a/intelligence_phishing_test.go b/intelligence_phishing_test.go index 67f7fcef4..f394b5ba0 100644 --- a/intelligence_phishing_test.go +++ b/intelligence_phishing_test.go @@ -3,9 +3,10 @@ package cloudflare import ( "context" "fmt" - "github.com/stretchr/testify/assert" "net/http" "testing" + + "github.com/stretchr/testify/assert" ) func TestIntelligence_PhishingScan(t *testing.T) { diff --git a/intelligence_whois_test.go b/intelligence_whois_test.go index 16a83b854..819dcfa89 100644 --- a/intelligence_whois_test.go +++ b/intelligence_whois_test.go @@ -3,9 +3,10 @@ package cloudflare import ( "context" "fmt" - "github.com/stretchr/testify/assert" "net/http" "testing" + + "github.com/stretchr/testify/assert" ) func TestIntelligence_WHOIS(t *testing.T) { diff --git a/ip_list.go b/ip_list.go index 96ed1c1af..d2f6a92ac 100644 --- a/ip_list.go +++ b/ip_list.go @@ -3,11 +3,10 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "time" - - "errors" ) // The definitions in this file are deprecated and should be removed after diff --git a/list.go b/list.go index 718f40c0b..75e802fe1 100644 --- a/list.go +++ b/list.go @@ -3,11 +3,10 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "time" - - "errors" ) const ( diff --git a/logpush.go b/logpush.go index 3c519df60..fbb5354f1 100644 --- a/logpush.go +++ b/logpush.go @@ -3,11 +3,10 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "time" - - "errors" ) // LogpushJob describes a Logpush job. diff --git a/magic_firewall_rulesets.go b/magic_firewall_rulesets.go index 3423d7e02..791f39703 100644 --- a/magic_firewall_rulesets.go +++ b/magic_firewall_rulesets.go @@ -3,11 +3,10 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "time" - - "errors" ) const ( diff --git a/magic_transit_gre_tunnel.go b/magic_transit_gre_tunnel.go index 6c7bf6b0c..fcab192c8 100644 --- a/magic_transit_gre_tunnel.go +++ b/magic_transit_gre_tunnel.go @@ -3,11 +3,10 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "time" - - "errors" ) // Magic Transit GRE Tunnel Error messages. diff --git a/magic_transit_ipsec_tunnel.go b/magic_transit_ipsec_tunnel.go index 1caecfd00..cf9076a51 100644 --- a/magic_transit_ipsec_tunnel.go +++ b/magic_transit_ipsec_tunnel.go @@ -3,11 +3,10 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "time" - - "errors" ) // Magic Transit IPsec Tunnel Error messages. diff --git a/magic_transit_static_routes.go b/magic_transit_static_routes.go index adf62ebec..1cce6cc92 100644 --- a/magic_transit_static_routes.go +++ b/magic_transit_static_routes.go @@ -3,11 +3,10 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "time" - - "errors" ) // Magic Transit Static Routes Error messages. diff --git a/miscategorization_test.go b/miscategorization_test.go index bf4928f0f..576b7dedf 100644 --- a/miscategorization_test.go +++ b/miscategorization_test.go @@ -3,9 +3,10 @@ package cloudflare import ( "context" "fmt" - "github.com/stretchr/testify/assert" "net/http" "testing" + + "github.com/stretchr/testify/assert" ) func TestCreateMiscategorization(t *testing.T) { diff --git a/origin_ca.go b/origin_ca.go index 22c62d975..a7eaea724 100644 --- a/origin_ca.go +++ b/origin_ca.go @@ -3,13 +3,12 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "io" "net/http" "net/url" "time" - - "errors" ) // OriginCACertificate represents a Cloudflare-issued certificate. diff --git a/page_rules.go b/page_rules.go index cb32bc272..033bd7fd2 100644 --- a/page_rules.go +++ b/page_rules.go @@ -24,42 +24,43 @@ type PageRuleTarget struct { PageRuleAction is the action to take when the target is matched. Valid IDs are: - always_online - always_use_https - automatic_https_rewrites - browser_cache_ttl - browser_check - bypass_cache_on_cookie - cache_by_device_type - cache_deception_armor - cache_level - cache_key_fields - cache_on_cookie - disable_apps - disable_performance - disable_railgun - disable_security - edge_cache_ttl - email_obfuscation - explicit_cache_control - forwarding_url - host_header_override - ip_geolocation - minify - mirage - opportunistic_encryption - origin_error_page_pass_thru - polish - resolve_override - respect_strong_etag - response_buffering - rocket_loader - security_level - server_side_exclude - sort_query_string_for_cache - ssl - true_client_ip_header - waf + + always_online + always_use_https + automatic_https_rewrites + browser_cache_ttl + browser_check + bypass_cache_on_cookie + cache_by_device_type + cache_deception_armor + cache_level + cache_key_fields + cache_on_cookie + disable_apps + disable_performance + disable_railgun + disable_security + edge_cache_ttl + email_obfuscation + explicit_cache_control + forwarding_url + host_header_override + ip_geolocation + minify + mirage + opportunistic_encryption + origin_error_page_pass_thru + polish + resolve_override + respect_strong_etag + response_buffering + rocket_loader + security_level + server_side_exclude + sort_query_string_for_cache + ssl + true_client_ip_header + waf */ type PageRuleAction struct { ID string `json:"id"` diff --git a/pages_deployment.go b/pages_deployment.go index c4f41e644..5229b6435 100644 --- a/pages_deployment.go +++ b/pages_deployment.go @@ -3,11 +3,10 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "time" - - "errors" ) // SizeOptions can be passed to a list request to configure size and cursor location. diff --git a/pages_domain_test.go b/pages_domain_test.go index 9e1e9d39e..20e80e7b4 100644 --- a/pages_domain_test.go +++ b/pages_domain_test.go @@ -3,10 +3,11 @@ package cloudflare import ( "context" "fmt" - "github.com/stretchr/testify/assert" "net/http" "testing" "time" + + "github.com/stretchr/testify/assert" ) const testPagesProjectName = "page-project" diff --git a/resource_group_test.go b/resource_group_test.go index ca4b6dc20..6f0ff3d36 100644 --- a/resource_group_test.go +++ b/resource_group_test.go @@ -2,8 +2,9 @@ package cloudflare import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestNewResourceGroup(t *testing.T) { diff --git a/rulesets.go b/rulesets.go index 9c7bea834..4a15f579f 100644 --- a/rulesets.go +++ b/rulesets.go @@ -3,12 +3,11 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "strings" "time" - - "errors" ) const ( diff --git a/secondary_dns_primaries.go b/secondary_dns_primaries.go index 7a81acfa9..4aa623c3e 100644 --- a/secondary_dns_primaries.go +++ b/secondary_dns_primaries.go @@ -3,10 +3,9 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" - - "errors" ) const ( diff --git a/secondary_dns_tsig.go b/secondary_dns_tsig.go index 71d8456b8..ed9a4bc41 100644 --- a/secondary_dns_tsig.go +++ b/secondary_dns_tsig.go @@ -3,10 +3,9 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" - - "errors" ) const ( diff --git a/secondary_dns_zone.go b/secondary_dns_zone.go index 41ee823f1..662a2f2bf 100644 --- a/secondary_dns_zone.go +++ b/secondary_dns_zone.go @@ -3,11 +3,10 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "time" - - "errors" ) const ( diff --git a/spectrum.go b/spectrum.go index 949813a75..8fe42b21e 100644 --- a/spectrum.go +++ b/spectrum.go @@ -3,14 +3,13 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net" "net/http" "strconv" "strings" "time" - - "errors" ) // ProxyProtocol implements json.Unmarshaler in order to support deserializing of the deprecated boolean diff --git a/teams_list.go b/teams_list.go index b4699a051..2f4300156 100644 --- a/teams_list.go +++ b/teams_list.go @@ -3,11 +3,10 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "time" - - "errors" ) var ErrMissingListID = errors.New("required missing list ID") diff --git a/tunnel.go b/tunnel.go index 3ed49f01b..d933eedfc 100644 --- a/tunnel.go +++ b/tunnel.go @@ -3,11 +3,10 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "time" - - "errors" ) // ErrMissingTunnelID is for when a required tunnel ID is missing from the diff --git a/tunnel_routes.go b/tunnel_routes.go index fbd48d8d3..0fba4eb3f 100644 --- a/tunnel_routes.go +++ b/tunnel_routes.go @@ -3,13 +3,12 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "net/url" "strings" "time" - - "errors" ) var ( diff --git a/tunnel_virtual_networks.go b/tunnel_virtual_networks.go index 2a22c2e67..a7ba6f408 100644 --- a/tunnel_virtual_networks.go +++ b/tunnel_virtual_networks.go @@ -3,11 +3,10 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "time" - - "errors" ) var ErrMissingVnetName = errors.New("required missing virtual network name") diff --git a/user_agent.go b/user_agent.go index 0c021424f..8c1a39207 100644 --- a/user_agent.go +++ b/user_agent.go @@ -3,12 +3,11 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "net/url" "strconv" - - "errors" ) // UserAgentRule represents a User-Agent Block. These rules can be used to diff --git a/web3_test.go b/web3_test.go index 44e0da5e5..690cbccc1 100644 --- a/web3_test.go +++ b/web3_test.go @@ -3,10 +3,11 @@ package cloudflare import ( "context" "fmt" - "github.com/stretchr/testify/assert" "net/http" "testing" "time" + + "github.com/stretchr/testify/assert" ) const testWeb3HostnameID = "9a7806061c88ada191ed06f989cc3dac" diff --git a/workers.go b/workers.go index 3b37de90d..dd4df618c 100644 --- a/workers.go +++ b/workers.go @@ -6,6 +6,7 @@ import ( rand "crypto/rand" "encoding/hex" "encoding/json" + "errors" "fmt" "io" "mime" @@ -14,8 +15,6 @@ import ( "net/textproto" "strings" "time" - - "errors" ) // WorkerRequestParams provides parameters for worker requests for both enterprise and standard requests. diff --git a/workers_kv.go b/workers_kv.go index 14ca55a42..39611f8fe 100644 --- a/workers_kv.go +++ b/workers_kv.go @@ -3,12 +3,11 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "net/url" "strconv" - - "errors" ) // WorkersKVNamespaceRequest provides parameters for creating and updating storage namespaces. diff --git a/workers_subdomain_test.go b/workers_subdomain_test.go index 33b12886e..d460cce02 100644 --- a/workers_subdomain_test.go +++ b/workers_subdomain_test.go @@ -3,9 +3,10 @@ package cloudflare import ( "context" "fmt" - "github.com/stretchr/testify/assert" "net/http" "testing" + + "github.com/stretchr/testify/assert" ) func TestWorkersSubdomain_CreateSubdomain(t *testing.T) { diff --git a/zone.go b/zone.go index 56d7da128..392935600 100644 --- a/zone.go +++ b/zone.go @@ -3,6 +3,7 @@ package cloudflare import ( "context" "encoding/json" + "errors" "fmt" "net/http" "net/url" @@ -10,8 +11,6 @@ import ( "sync" "time" - "errors" - "golang.org/x/net/idna" )