Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore(encoding): dropped go-json direct dependency #2033

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion mod/primitives/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240703145037-b5612ab256db
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240610210054-bfdc14c4013c
github.com/ferranbt/fastssz v0.1.4-0.20240629094022-eac385e6ee79
github.com/goccy/go-json v0.10.3
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/holiman/uint256 v1.3.1
github.com/karalabe/ssz v0.2.1-0.20240724074312-3d1ff7a6f7c4
Expand Down
2 changes: 0 additions & 2 deletions mod/primitives/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ github.com/getsentry/sentry-go v0.28.1 h1:zzaSm/vHmGllRM6Tpx1492r0YDzauArdBfkJRt
github.com/getsentry/sentry-go v0.28.1/go.mod h1:1fQZ+7l7eeJ3wYi82q5Hg8GqAPgefRq+FP/QhafYVgg=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
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/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
Expand Down
12 changes: 5 additions & 7 deletions mod/primitives/pkg/encoding/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,27 @@ package json

import (
"encoding/json"

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

// Marshaler is the interface implemented by types that
// can marshal themselves into valid JSON.
type Marshaler = gojson.Marshaler
type Marshaler = json.Marshaler

// Unmarshaler is the interface implemented by types
// that can unmarshal a JSON description of themselves.
type Unmarshaler = gojson.Unmarshaler
type Unmarshaler = json.Unmarshaler

// Marshal is a wrapper for gojson.Marshal, which provides high-performance JSON
// encoding.
var Marshal = gojson.Marshal
var Marshal = json.Marshal

// MarshalIndent is a wrapper for gojson.MarshalIndent, which provides
// high-performance JSON encoding with indentation.
var MarshalIndent = gojson.MarshalIndent
var MarshalIndent = json.MarshalIndent

// Unmarshal is a wrapper for gojson.Unmarshal, which provides high-performance
// JSON decoding.
var Unmarshal = gojson.Unmarshal
var Unmarshal = json.Unmarshal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Overall LGTM! Consider performance impact and thorough testing.

The changes in this file consistently replace gojson with the standard encoding/json package, aligning well with the PR objective of dropping the direct dependency on go-json. All individual changes look good.

Recommendations:

  1. Run the verification scripts provided in the previous comments to ensure no usage of gojson-specific features in the codebase.
  2. Conduct thorough testing, especially for any performance-critical sections that use these JSON functions.
  3. Consider running benchmarks to compare the performance of encoding/json vs go-json for your specific use cases.
  4. Update any documentation or comments that might reference go-json.

Given that go-json remains an indirect dependency, consider evaluating if it can be completely removed from the project in the future to further simplify the dependency structure.


// RawMessage is an alias for json.RawMessage, represensting a raw encoded JSON
// value. It implements Marshaler and Unmarshaler and can be used to delay JSON
Expand Down
Loading