| 1 |
// Copyright 2023 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
//go:build goexperiment.jsonv2 |
| 6 |
|
| 7 |
package internal |
| 8 |
|
| 9 |
import "errors" |
| 10 |
|
| 11 |
// NotForPublicUse is a marker type that an API is for internal use only. |
| 12 |
// It does not perfectly prevent usage of that API, but helps to restrict usage. |
| 13 |
// Anything with this marker is not covered by the Go compatibility agreement. |
| 14 |
type NotForPublicUse struct{} |
| 15 |
|
| 16 |
// AllowInternalUse is passed from "json" to "jsontext" to authenticate |
| 17 |
// that the caller can have access to internal functionality. |
| 18 |
var AllowInternalUse NotForPublicUse |
| 19 |
|
| 20 |
// Sentinel error values internally shared between jsonv1 and jsonv2. |
| 21 |
var ( |
| 22 |
ErrCycle = errors.New("encountered a cycle") |
| 23 |
ErrNonNilReference = errors.New("value must be passed as a non-nil pointer reference") |
| 24 |
) |
| 25 |
|
| 26 |
var ( |
| 27 |
// TransformMarshalError converts a v2 error into a v1 error. |
| 28 |
// It is called only at the top-level of a Marshal function. |
| 29 |
TransformMarshalError func(any, error) error |
| 30 |
// NewMarshalerError constructs a jsonv1.MarshalerError. |
| 31 |
// It is called after a user-defined Marshal method/function fails. |
| 32 |
NewMarshalerError func(any, error, string) error |
| 33 |
// TransformUnmarshalError converts a v2 error into a v1 error. |
| 34 |
// It is called only at the top-level of a Unmarshal function. |
| 35 |
TransformUnmarshalError func(any, error) error |
| 36 |
|
| 37 |
// NewRawNumber returns new(jsonv1.Number). |
| 38 |
NewRawNumber func() any |
| 39 |
// RawNumberOf returns jsonv1.Number(b). |
| 40 |
RawNumberOf func(b []byte) any |
| 41 |
) |