migrate go version to 1.17 (#203)

* migrate go version to 1.17

* update contributing
This commit is contained in:
tobi
2021-09-10 14:42:14 +02:00
committed by GitHub
parent e681aac589
commit f2e5bedea6
282 changed files with 11863 additions and 12600 deletions

View File

@ -2,6 +2,7 @@ package json
import (
"bytes"
"context"
"encoding/json"
"github.com/goccy/go-json/internal/encoder"
@ -13,6 +14,12 @@ type Marshaler interface {
MarshalJSON() ([]byte, error)
}
// MarshalerContext is the interface implemented by types that
// can marshal themselves into valid JSON with context.Context.
type MarshalerContext interface {
MarshalJSON(context.Context) ([]byte, error)
}
// Unmarshaler is the interface implemented by types
// that can unmarshal a JSON description of themselves.
// The input can be assumed to be a valid encoding of
@ -25,6 +32,12 @@ type Unmarshaler interface {
UnmarshalJSON([]byte) error
}
// UnmarshalerContext is the interface implemented by types
// that can unmarshal with context.Context a JSON description of themselves.
type UnmarshalerContext interface {
UnmarshalJSON(context.Context, []byte) error
}
// Marshal returns the JSON encoding of v.
//
// Marshal traverses the value v recursively.
@ -158,18 +171,19 @@ func Marshal(v interface{}) ([]byte, error) {
return MarshalWithOption(v)
}
// MarshalNoEscape
// MarshalNoEscape returns the JSON encoding of v and doesn't escape v.
func MarshalNoEscape(v interface{}) ([]byte, error) {
return marshalNoEscape(v, EncodeOptionHTMLEscape)
return marshalNoEscape(v)
}
// MarshalContext returns the JSON encoding of v with context.Context and EncodeOption.
func MarshalContext(ctx context.Context, v interface{}, optFuncs ...EncodeOptionFunc) ([]byte, error) {
return marshalContext(ctx, v, optFuncs...)
}
// MarshalWithOption returns the JSON encoding of v with EncodeOption.
func MarshalWithOption(v interface{}, optFuncs ...EncodeOptionFunc) ([]byte, error) {
opt := EncodeOptionHTMLEscape
for _, optFunc := range optFuncs {
opt = optFunc(opt)
}
return marshal(v, opt)
return marshal(v, optFuncs...)
}
// MarshalIndent is like Marshal but applies Indent to format the output.
@ -181,11 +195,7 @@ func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) {
// MarshalIndentWithOption is like Marshal but applies Indent to format the output with EncodeOption.
func MarshalIndentWithOption(v interface{}, prefix, indent string, optFuncs ...EncodeOptionFunc) ([]byte, error) {
opt := EncodeOptionHTMLEscape | EncodeOptionIndent
for _, optFunc := range optFuncs {
opt = optFunc(opt)
}
return marshalIndent(v, prefix, indent, opt)
return marshalIndent(v, prefix, indent, optFuncs...)
}
// Unmarshal parses the JSON-encoded data and stores the result
@ -266,8 +276,19 @@ func Unmarshal(data []byte, v interface{}) error {
return unmarshal(data, v)
}
func UnmarshalNoEscape(data []byte, v interface{}) error {
return unmarshalNoEscape(data, v)
// UnmarshalContext parses the JSON-encoded data and stores the result
// in the value pointed to by v. If you implement the UnmarshalerContext interface,
// call it with ctx as an argument.
func UnmarshalContext(ctx context.Context, data []byte, v interface{}, optFuncs ...DecodeOptionFunc) error {
return unmarshalContext(ctx, data, v)
}
func UnmarshalWithOption(data []byte, v interface{}, optFuncs ...DecodeOptionFunc) error {
return unmarshal(data, v, optFuncs...)
}
func UnmarshalNoEscape(data []byte, v interface{}, optFuncs ...DecodeOptionFunc) error {
return unmarshalNoEscape(data, v, optFuncs...)
}
// A Token holds a value of one of these types:
@ -326,7 +347,7 @@ func HTMLEscape(dst *bytes.Buffer, src []byte) {
if err := dec.Decode(&v); err != nil {
return
}
buf, _ := marshal(v, EncodeOptionHTMLEscape)
buf, _ := marshal(v)
dst.Write(buf)
}