Skip to content

Commit

Permalink
tuning: json encoding/decoding by go-json
Browse files Browse the repository at this point in the history
  • Loading branch information
lkeix committed Dec 4, 2024
1 parent f5f8ca1 commit ecf08be
Show file tree
Hide file tree
Showing 52 changed files with 54 additions and 48 deletions.
1 change: 1 addition & 0 deletions _examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
require (
github.com/agnivade/levenshtein v1.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/logrusorgru/aurora/v4 v4.0.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down
2 changes: 2 additions & 0 deletions _examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54 h1:SG7nF6SRlWhcT7c
github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss=
github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
Expand Down
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package client

import (
"bytes"
"encoding/json"
"github.com/goccy/go-json"
"fmt"
"io"
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package client_test

import (
"bytes"
"encoding/json"
"github.com/goccy/go-json"
"fmt"
"io"
"mime/multipart"
Expand Down
2 changes: 1 addition & 1 deletion client/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package client

import "encoding/json"
import "github.com/goccy/go-json"

// RawJsonError is a json formatted error from a GraphQL server.
type RawJsonError struct {
Expand Down
2 changes: 1 addition & 1 deletion client/sse.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package client
import (
"bufio"
"context"
"encoding/json"
"github.com/goccy/go-json"
"fmt"
"net/http/httptest"
"net/textproto"
Expand Down
2 changes: 1 addition & 1 deletion client/websocket.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
"encoding/json"
"github.com/goccy/go-json"
"errors"
"fmt"
"io"
Expand Down
2 changes: 1 addition & 1 deletion client/withfilesoption.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package client

import (
"bytes"
"encoding/json"
"github.com/goccy/go-json"
"fmt"
"io"
"mime/multipart"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package followschema

import (
"encoding/json"
"github.com/goccy/go-json"
"errors"
"io"
"regexp"
Expand Down
2 changes: 1 addition & 1 deletion codegen/testserver/singlefile/defer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package singlefile
import (
"cmp"
"context"
"encoding/json"
"github.com/goccy/go-json"
"math/rand"
"reflect"
"slices"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package singlefile

import (
"encoding/json"
"github.com/goccy/go-json"
"errors"
"io"
"regexp"
Expand Down
2 changes: 1 addition & 1 deletion docs/content/recipes/federation.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ genrated resolver functions that include a new argument, `federationRequires`, t
fields you requested in your `@requires.fields` selection set.

> Note: currently it's represented as a map[string]any where the contained values are encoded with
`encoding/json`. Eventually we will generate a typesafe model that represents these models,
`github.com/goccy/go-json`. Eventually we will generate a typesafe model that represents these models,
however that is a large lift. This typesafe support will be added in the future.

### Example
Expand Down
2 changes: 1 addition & 1 deletion docs/content/reference/model-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ advantageous, or even necessary, to have control over some aspects of this outpu
## json ",omitempty"

By default, fields that are marked as nullable in the GraphQL schema, e.g. `field: String` rather than `field: String!`,
have the [json ",omitempty"](https://pkg.go.dev/encoding/json#Marshal) field tag applied to them. This is probably fine
have the [json ",omitempty"](https://pkg.go.dev/github.com/goccy/go-json#Marshal) field tag applied to them. This is probably fine
if the downstream consumers of json serialized representations of this model are all written in Go, but obviously this
is not always true.

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54 h1:SG7nF6SRlWhcT7c
github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss=
github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
Expand Down
2 changes: 1 addition & 1 deletion graphql/any.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package graphql

import (
"encoding/json"
"github.com/goccy/go-json"
"io"
)

Expand Down
2 changes: 1 addition & 1 deletion graphql/coercion.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package graphql

import (
"encoding/json"
"github.com/goccy/go-json"
)

// CoerceList applies coercion from a single value to a list.
Expand Down
2 changes: 1 addition & 1 deletion graphql/coercion_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package graphql

import (
"encoding/json"
"github.com/goccy/go-json"
"testing"

"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion graphql/executor/testexecutor/testexecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package testexecutor
import (
"bytes"
"context"
"encoding/json"
"github.com/goccy/go-json"
"errors"
"fmt"
"io"
Expand Down
2 changes: 1 addition & 1 deletion graphql/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package graphql

import (
"context"
"encoding/json"
"github.com/goccy/go-json"
"errors"
"fmt"
"io"
Expand Down
2 changes: 1 addition & 1 deletion graphql/handler/apollofederatedtracingv1/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package apollofederatedtracingv1_test
import (
"context"
"encoding/base64"
"encoding/json"
"github.com/goccy/go-json"
"io"
"net/http"
"net/http/httptest"
Expand Down
2 changes: 1 addition & 1 deletion graphql/handler/apollotracing/tracer_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package apollotracing_test

import (
"encoding/json"
"github.com/goccy/go-json"
"io"
"net/http"
"net/http/httptest"
Expand Down
2 changes: 1 addition & 1 deletion graphql/handler/debug/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package debug

import (
"context"
"encoding/json"
"github.com/goccy/go-json"
"fmt"
"io"
"os"
Expand Down
2 changes: 1 addition & 1 deletion graphql/handler/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package handler

import (
"context"
"encoding/json"
"github.com/goccy/go-json"
"errors"
"fmt"
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion graphql/handler/transport/error.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package transport

import (
"encoding/json"
"github.com/goccy/go-json"
"fmt"
"net/http"

Expand Down
2 changes: 1 addition & 1 deletion graphql/handler/transport/http_form_multipart.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package transport

import (
"encoding/json"
"github.com/goccy/go-json"
"io"
"mime"
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion graphql/handler/transport/http_get.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package transport

import (
"encoding/json"
"github.com/goccy/go-json"
"io"
"net/http"
"net/url"
Expand Down
2 changes: 1 addition & 1 deletion graphql/handler/transport/http_multipart_mixed.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package transport

import (
"encoding/json"
"github.com/goccy/go-json"
"fmt"
"io"
"log"
Expand Down
2 changes: 1 addition & 1 deletion graphql/handler/transport/sse.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package transport

import (
"encoding/json"
"github.com/goccy/go-json"
"fmt"
"io"
"log"
Expand Down
2 changes: 1 addition & 1 deletion graphql/handler/transport/util.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package transport

import (
"encoding/json"
"github.com/goccy/go-json"
"fmt"
"io"

Expand Down
2 changes: 1 addition & 1 deletion graphql/handler/transport/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package transport
import (
"bytes"
"context"
"encoding/json"
"github.com/goccy/go-json"
"errors"
"fmt"
"log"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package transport

import (
"encoding/json"
"github.com/goccy/go-json"
"fmt"

"github.com/gorilla/websocket"
Expand Down
2 changes: 1 addition & 1 deletion graphql/handler/transport/websocket_graphqlws.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package transport

import (
"encoding/json"
"github.com/goccy/go-json"
"fmt"

"github.com/gorilla/websocket"
Expand Down
2 changes: 1 addition & 1 deletion graphql/handler/transport/websocket_subprotocol.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package transport

import (
"encoding/json"
"github.com/goccy/go-json"
"errors"

"github.com/gorilla/websocket"
Expand Down
2 changes: 1 addition & 1 deletion graphql/handler/transport/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package transport_test

import (
"context"
"encoding/json"
"github.com/goccy/go-json"
"errors"
"net/http"
"net/http/httptest"
Expand Down
2 changes: 1 addition & 1 deletion graphql/id.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package graphql

import (
"encoding/json"
"github.com/goccy/go-json"
"fmt"
"io"
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion graphql/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package graphql

import (
"bytes"
"encoding/json"
"github.com/goccy/go-json"
"math"
"testing"

Expand Down
2 changes: 1 addition & 1 deletion graphql/int.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package graphql

import (
"encoding/json"
"github.com/goccy/go-json"
"fmt"
"io"
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion graphql/int_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package graphql

import (
"encoding/json"
"github.com/goccy/go-json"
"testing"

"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion graphql/map.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package graphql

import (
"encoding/json"
"github.com/goccy/go-json"
"fmt"
"io"
)
Expand Down
2 changes: 1 addition & 1 deletion graphql/omittable.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package graphql

import "encoding/json"
import "github.com/goccy/go-json"

// Omittable is a wrapper around a value that also stores whether it is set
// or not.
Expand Down
2 changes: 1 addition & 1 deletion graphql/omittable_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package graphql

import (
"encoding/json"
"github.com/goccy/go-json"
"testing"

"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion graphql/playground/apollo_sandbox_playground.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package playground

import (
"encoding/json"
"github.com/goccy/go-json"
"fmt"
"html/template"
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion graphql/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package graphql

import (
"context"
"encoding/json"
"github.com/goccy/go-json"
"fmt"

"github.com/vektah/gqlparser/v2/ast"
Expand Down
Loading

0 comments on commit ecf08be

Please sign in to comment.