forked from meghfossa/example-projects
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
143 changed files
with
19,099 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module path_deps | ||
|
||
go 1.18 | ||
|
||
require ( | ||
github.com/ajankovic/xdiff v0.0.1 | ||
github.com/json-iterator/go v1.1.12 | ||
github.com/prometheus/client_golang v1.12.2 | ||
) | ||
|
||
require ( | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/cespare/xxhash/v2 v2.1.2 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/prometheus/client_model v0.2.0 // indirect | ||
github.com/prometheus/common v0.32.1 // indirect | ||
github.com/prometheus/procfs v0.7.3 // indirect | ||
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect | ||
google.golang.org/protobuf v1.26.0 // indirect | ||
) | ||
|
||
replace ( | ||
github.com/json-iterator/go v1.1.12 => ./local_pkgs/json-iterator/go | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ignore: | ||
- "output_tests/.*" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/vendor | ||
/bug_test.go | ||
/coverage.txt | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
language: go | ||
|
||
go: | ||
- 1.8.x | ||
- 1.x | ||
|
||
before_install: | ||
- go get -t -v ./... | ||
|
||
script: | ||
- ./test.sh | ||
|
||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Gopkg.toml example | ||
# | ||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
|
||
ignored = ["github.com/davecgh/go-spew*","github.com/google/gofuzz*","github.com/stretchr/testify*"] | ||
|
||
[[constraint]] | ||
name = "github.com/modern-go/reflect2" | ||
version = "1.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2016 json-iterator | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
[![Sourcegraph](https://sourcegraph.com/github.com/json-iterator/go/-/badge.svg)](https://sourcegraph.com/github.com/json-iterator/go?badge) | ||
[![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://pkg.go.dev/github.com/json-iterator/go) | ||
[![Build Status](https://travis-ci.org/json-iterator/go.svg?branch=master)](https://travis-ci.org/json-iterator/go) | ||
[![codecov](https://codecov.io/gh/json-iterator/go/branch/master/graph/badge.svg)](https://codecov.io/gh/json-iterator/go) | ||
[![rcard](https://goreportcard.com/badge/github.com/json-iterator/go)](https://goreportcard.com/report/github.com/json-iterator/go) | ||
[![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/json-iterator/go/master/LICENSE) | ||
[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/json-iterator/Lobby) | ||
|
||
A high-performance 100% compatible drop-in replacement of "encoding/json" | ||
|
||
# Benchmark | ||
|
||
![benchmark](http://jsoniter.com/benchmarks/go-benchmark.png) | ||
|
||
Source code: https://github.com/json-iterator/go-benchmark/blob/master/src/github.com/json-iterator/go-benchmark/benchmark_medium_payload_test.go | ||
|
||
Raw Result (easyjson requires static code generation) | ||
|
||
| | ns/op | allocation bytes | allocation times | | ||
| --------------- | ----------- | ---------------- | ---------------- | | ||
| std decode | 35510 ns/op | 1960 B/op | 99 allocs/op | | ||
| easyjson decode | 8499 ns/op | 160 B/op | 4 allocs/op | | ||
| jsoniter decode | 5623 ns/op | 160 B/op | 3 allocs/op | | ||
| std encode | 2213 ns/op | 712 B/op | 5 allocs/op | | ||
| easyjson encode | 883 ns/op | 576 B/op | 3 allocs/op | | ||
| jsoniter encode | 837 ns/op | 384 B/op | 4 allocs/op | | ||
|
||
Always benchmark with your own workload. | ||
The result depends heavily on the data input. | ||
|
||
# Usage | ||
|
||
100% compatibility with standard lib | ||
|
||
Replace | ||
|
||
```go | ||
import "encoding/json" | ||
json.Marshal(&data) | ||
``` | ||
|
||
with | ||
|
||
```go | ||
import jsoniter "github.com/json-iterator/go" | ||
|
||
var json = jsoniter.ConfigCompatibleWithStandardLibrary | ||
json.Marshal(&data) | ||
``` | ||
|
||
Replace | ||
|
||
```go | ||
import "encoding/json" | ||
json.Unmarshal(input, &data) | ||
``` | ||
|
||
with | ||
|
||
```go | ||
import jsoniter "github.com/json-iterator/go" | ||
|
||
var json = jsoniter.ConfigCompatibleWithStandardLibrary | ||
json.Unmarshal(input, &data) | ||
``` | ||
|
||
[More documentation](http://jsoniter.com/migrate-from-go-std.html) | ||
|
||
# How to get | ||
|
||
``` | ||
go get github.com/json-iterator/go | ||
``` | ||
|
||
# Contribution Welcomed ! | ||
|
||
Contributors | ||
|
||
- [thockin](https://github.com/thockin) | ||
- [mattn](https://github.com/mattn) | ||
- [cch123](https://github.com/cch123) | ||
- [Oleg Shaldybin](https://github.com/olegshaldybin) | ||
- [Jason Toffaletti](https://github.com/toffaletti) | ||
|
||
Report issue or pull request, or email taowen@gmail.com, or [![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/json-iterator/Lobby) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package jsoniter | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
) | ||
|
||
// RawMessage to make replace json with jsoniter | ||
type RawMessage []byte | ||
|
||
// Unmarshal adapts to json/encoding Unmarshal API | ||
// | ||
// Unmarshal parses the JSON-encoded data and stores the result in the value pointed to by v. | ||
// Refer to https://godoc.org/encoding/json#Unmarshal for more information | ||
func Unmarshal(data []byte, v interface{}) error { | ||
return ConfigDefault.Unmarshal(data, v) | ||
} | ||
|
||
// UnmarshalFromString is a convenient method to read from string instead of []byte | ||
func UnmarshalFromString(str string, v interface{}) error { | ||
return ConfigDefault.UnmarshalFromString(str, v) | ||
} | ||
|
||
// Get quick method to get value from deeply nested JSON structure | ||
func Get(data []byte, path ...interface{}) Any { | ||
return ConfigDefault.Get(data, path...) | ||
} | ||
|
||
// Marshal adapts to json/encoding Marshal API | ||
// | ||
// Marshal returns the JSON encoding of v, adapts to json/encoding Marshal API | ||
// Refer to https://godoc.org/encoding/json#Marshal for more information | ||
func Marshal(v interface{}) ([]byte, error) { | ||
return ConfigDefault.Marshal(v) | ||
} | ||
|
||
// MarshalIndent same as json.MarshalIndent. Prefix is not supported. | ||
func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { | ||
return ConfigDefault.MarshalIndent(v, prefix, indent) | ||
} | ||
|
||
// MarshalToString convenient method to write as string instead of []byte | ||
func MarshalToString(v interface{}) (string, error) { | ||
return ConfigDefault.MarshalToString(v) | ||
} | ||
|
||
// NewDecoder adapts to json/stream NewDecoder API. | ||
// | ||
// NewDecoder returns a new decoder that reads from r. | ||
// | ||
// Instead of a json/encoding Decoder, an Decoder is returned | ||
// Refer to https://godoc.org/encoding/json#NewDecoder for more information | ||
func NewDecoder(reader io.Reader) *Decoder { | ||
return ConfigDefault.NewDecoder(reader) | ||
} | ||
|
||
// Decoder reads and decodes JSON values from an input stream. | ||
// Decoder provides identical APIs with json/stream Decoder (Token() and UseNumber() are in progress) | ||
type Decoder struct { | ||
iter *Iterator | ||
} | ||
|
||
// Decode decode JSON into interface{} | ||
func (adapter *Decoder) Decode(obj interface{}) error { | ||
if adapter.iter.head == adapter.iter.tail && adapter.iter.reader != nil { | ||
if !adapter.iter.loadMore() { | ||
return io.EOF | ||
} | ||
} | ||
adapter.iter.ReadVal(obj) | ||
err := adapter.iter.Error | ||
if err == io.EOF { | ||
return nil | ||
} | ||
return adapter.iter.Error | ||
} | ||
|
||
// More is there more? | ||
func (adapter *Decoder) More() bool { | ||
iter := adapter.iter | ||
if iter.Error != nil { | ||
return false | ||
} | ||
c := iter.nextToken() | ||
if c == 0 { | ||
return false | ||
} | ||
iter.unreadByte() | ||
return c != ']' && c != '}' | ||
} | ||
|
||
// Buffered remaining buffer | ||
func (adapter *Decoder) Buffered() io.Reader { | ||
remaining := adapter.iter.buf[adapter.iter.head:adapter.iter.tail] | ||
return bytes.NewReader(remaining) | ||
} | ||
|
||
// UseNumber causes the Decoder to unmarshal a number into an interface{} as a | ||
// Number instead of as a float64. | ||
func (adapter *Decoder) UseNumber() { | ||
cfg := adapter.iter.cfg.configBeforeFrozen | ||
cfg.UseNumber = true | ||
adapter.iter.cfg = cfg.frozeWithCacheReuse(adapter.iter.cfg.extraExtensions) | ||
} | ||
|
||
// DisallowUnknownFields causes the Decoder to return an error when the destination | ||
// is a struct and the input contains object keys which do not match any | ||
// non-ignored, exported fields in the destination. | ||
func (adapter *Decoder) DisallowUnknownFields() { | ||
cfg := adapter.iter.cfg.configBeforeFrozen | ||
cfg.DisallowUnknownFields = true | ||
adapter.iter.cfg = cfg.frozeWithCacheReuse(adapter.iter.cfg.extraExtensions) | ||
} | ||
|
||
// NewEncoder same as json.NewEncoder | ||
func NewEncoder(writer io.Writer) *Encoder { | ||
return ConfigDefault.NewEncoder(writer) | ||
} | ||
|
||
// Encoder same as json.Encoder | ||
type Encoder struct { | ||
stream *Stream | ||
} | ||
|
||
// Encode encode interface{} as JSON to io.Writer | ||
func (adapter *Encoder) Encode(val interface{}) error { | ||
adapter.stream.WriteVal(val) | ||
adapter.stream.WriteRaw("\n") | ||
adapter.stream.Flush() | ||
return adapter.stream.Error | ||
} | ||
|
||
// SetIndent set the indention. Prefix is not supported | ||
func (adapter *Encoder) SetIndent(prefix, indent string) { | ||
config := adapter.stream.cfg.configBeforeFrozen | ||
config.IndentionStep = len(indent) | ||
adapter.stream.cfg = config.frozeWithCacheReuse(adapter.stream.cfg.extraExtensions) | ||
} | ||
|
||
// SetEscapeHTML escape html by default, set to false to disable | ||
func (adapter *Encoder) SetEscapeHTML(escapeHTML bool) { | ||
config := adapter.stream.cfg.configBeforeFrozen | ||
config.EscapeHTML = escapeHTML | ||
adapter.stream.cfg = config.frozeWithCacheReuse(adapter.stream.cfg.extraExtensions) | ||
} | ||
|
||
// Valid reports whether data is a valid JSON encoding. | ||
func Valid(data []byte) bool { | ||
return ConfigDefault.Valid(data) | ||
} |
Oops, something went wrong.