Skip to content

Commit

Permalink
replace encoding/json with github.com/goccy/go-json
Browse files Browse the repository at this point in the history
The stdlib has some, ermm, quirks with how certain methods handle strings
without a way to customise that behaviour. This bites us in cases where our API
payloads (represented as bytes) *shouldn't* be escaping HTML entities however
they end up escaped and won't match our internal representation of them.

Instead of doing hacky work arounds, I've just swapped out `encoding/json` with
`github.com/goccy/go-json` which mentions it is a drop in replacement but, it
includes a way to customise certain behaviours as needed.
  • Loading branch information
jacobbednarz committed Aug 7, 2023
1 parent 9869ab9 commit 7e066fe
Show file tree
Hide file tree
Showing 151 changed files with 291 additions and 153 deletions.
3 changes: 2 additions & 1 deletion access_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

// AccessApplicationType represents the application type.
Expand Down
3 changes: 2 additions & 1 deletion access_audit_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
"time"

"github.com/goccy/go-json"
)

// AccessAuditLogRecord is the structure of a single Access Audit Log entry.
Expand Down
3 changes: 2 additions & 1 deletion access_audit_log_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare_test

import (
"context"
"encoding/json"
"fmt"
"log"

"github.com/goccy/go-json"

cloudflare "github.com/cloudflare/cloudflare-go"
)

Expand Down
3 changes: 2 additions & 1 deletion access_bookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

// AccessBookmark represents an Access bookmark application.
Expand Down
3 changes: 2 additions & 1 deletion access_ca_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"

"github.com/goccy/go-json"
)

// AccessCACertificate is the structure of the CA certificate used for
Expand Down
3 changes: 2 additions & 1 deletion access_custom_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"

"github.com/goccy/go-json"
)

var ErrMissingUID = errors.New("required UID missing")
Expand Down
3 changes: 2 additions & 1 deletion access_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

// AccessGroup defines a group for allowing or disallowing access to
Expand Down
3 changes: 2 additions & 1 deletion access_identity_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"

"github.com/goccy/go-json"
)

// AccessIdentityProvider is the structure of the provider object.
Expand Down
3 changes: 2 additions & 1 deletion access_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

type AccessKeysConfig struct {
Expand Down
2 changes: 1 addition & 1 deletion access_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"testing"
"time"

"github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
)

Expand Down
3 changes: 2 additions & 1 deletion access_mutual_tls_certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

// AccessMutualTLSCertificate is the structure of a single Access Mutual TLS
Expand Down
3 changes: 2 additions & 1 deletion access_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

// AccessOrganization represents an Access organization.
Expand Down
3 changes: 2 additions & 1 deletion access_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package cloudflare

import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion access_service_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package cloudflare

import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion account_members.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"

"github.com/goccy/go-json"
)

// AccountMember is the definition of a member of an account.
Expand Down
3 changes: 2 additions & 1 deletion account_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"

"github.com/goccy/go-json"
)

// AccountRole defines the roles that a member can have attached.
Expand Down
3 changes: 2 additions & 1 deletion accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

// AccountSettings outlines the available options for an account.
Expand Down
3 changes: 2 additions & 1 deletion addressing_address_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

// AddressMap contains information about an address map.
Expand Down
3 changes: 2 additions & 1 deletion addressing_ip_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

// IPPrefix contains information about an IP prefix.
Expand Down
3 changes: 2 additions & 1 deletion api_shield.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"

"github.com/goccy/go-json"
)

// AuthIdCharacteristics a single option from
Expand Down
3 changes: 2 additions & 1 deletion api_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

// APIToken is the full API token.
Expand Down
3 changes: 2 additions & 1 deletion argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

var validSettingValues = []string{"on", "off"}
Expand Down
3 changes: 2 additions & 1 deletion argo_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

// ArgoTunnel is the struct definition of a tunnel.
Expand Down
3 changes: 2 additions & 1 deletion auditlogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package cloudflare

import (
"context"
"encoding/json"
"net/http"
"net/url"
"path"
"strconv"
"time"

"github.com/goccy/go-json"
)

// AuditLogAction is a member of AuditLog, the action that was taken.
Expand Down
3 changes: 2 additions & 1 deletion authenticated_origin_pulls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

// AuthenticatedOriginPulls represents global AuthenticatedOriginPulls (tls_client_auth) metadata.
Expand Down
3 changes: 2 additions & 1 deletion authenticated_origin_pulls_per_hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

// PerHostnameAuthenticatedOriginPullsCertificateDetails represents the metadata for a Per Hostname AuthenticatedOriginPulls certificate.
Expand Down
3 changes: 2 additions & 1 deletion authenticated_origin_pulls_per_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

// PerZoneAuthenticatedOriginPullsSettings represents the settings for Per Zone AuthenticatedOriginPulls.
Expand Down
3 changes: 2 additions & 1 deletion cache_reserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

// CacheReserve is the structure of the API object for the cache reserve
Expand Down
3 changes: 2 additions & 1 deletion certificate_packs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudflare

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/goccy/go-json"
)

// CertificatePackGeoRestrictions is for the structure of the geographic
Expand Down
3 changes: 2 additions & 1 deletion cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package cloudflare
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
Expand All @@ -18,6 +17,8 @@ import (
"strings"
"time"

"github.com/goccy/go-json"

"golang.org/x/time/rate"
)

Expand Down
Loading

0 comments on commit 7e066fe

Please sign in to comment.