mirror of
https://github.com/gin-gonic/gin.git
synced 2026-05-14 19:38:26 +08:00
1.7 KiB
1.7 KiB
What problem does this PR solve?
Issue Number: Close #2810
Problem Summary:
Users have requested an example of how to integrate json-iterator with Gin at runtime (without using build tags). While there is documentation, a runnable example project is helpful for understanding the integration points, specifically implementing the json.Core interface and replacing json.API.
What is changed and how does it work?
- Added a new example under
examples/json-iterator. - Implemented
customJsonApiwhich wrapsjsoniter.Configand implementsjson.Core. - Demonstrates how to replace the default
json.APIwith the custom implementation. - Added a unit test to verify the integration works as expected.
- Added a README for the example explaining how to run and test it.
Check List
Tests
- Unit test
- Added
examples/json-iterator/json_iterator_test.go
- Added
- Integration test
- Manual test
- Verified with
curllocally.
- Verified with
- No code
Code changes
- Has the configuration change
- Has HTTP API interfaces changed
- Has persistent data change
Side effects
- Possible performance regression
- Increased code complexity
- Breaking backward compatibility
Related changes
- PR to update
pingcap/docs/pingcap/docs-cn: - PR to update
pingcap/tiup: - Need to cherry-pick to the release branch
How to Test
- Navigate to the example directory:
cd examples/json-iterator - Run the tests:
go test -v - Run the example:
go run main.go - Make a request:
curl http://localhost:8080/ping