diff options
author | 2021-09-10 14:42:14 +0200 | |
---|---|---|
committer | 2021-09-10 14:42:14 +0200 | |
commit | f2e5bedea6fb93fbbf68ed8f7153c353cc57a9f0 (patch) | |
tree | 475ae9e7470d0df670ab2a59dce351cd1d07498a /vendor/github.com/goccy/go-json/json.go | |
parent | fixes + db changes (#204) (diff) | |
download | gotosocial-f2e5bedea6fb93fbbf68ed8f7153c353cc57a9f0.tar.xz |
migrate go version to 1.17 (#203)
* migrate go version to 1.17
* update contributing
Diffstat (limited to 'vendor/github.com/goccy/go-json/json.go')
-rw-r--r-- | vendor/github.com/goccy/go-json/json.go | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/vendor/github.com/goccy/go-json/json.go b/vendor/github.com/goccy/go-json/json.go index 05756efa3..5c9448d8c 100644 --- a/vendor/github.com/goccy/go-json/json.go +++ b/vendor/github.com/goccy/go-json/json.go @@ -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) } |