| 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 || !go1.25 |
| 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 | ErrNilInterface = errors.New("cannot derive concrete type for nil interface with finite type set") |
| 25 | ) |
| 26 | |
| 27 | var ( |
| 28 | // TransformMarshalError converts a v2 error into a v1 error. |
| 29 | // It is called only at the top-level of a Marshal function. |
| 30 | TransformMarshalError func(any, error) error |
| 31 | // NewMarshalerError constructs a jsonv1.MarshalerError. |
| 32 | // It is called after a user-defined Marshal method/function fails. |
| 33 | NewMarshalerError func(any, error, string) error |
| 34 | // TransformUnmarshalError converts a v2 error into a v1 error. |
| 35 | // It is called only at the top-level of a Unmarshal function. |
| 36 | TransformUnmarshalError func(any, error) error |
| 37 | |
| 38 | // NewRawNumber returns new(jsonv1.Number). |
| 39 | NewRawNumber func() any |
| 40 | // RawNumberOf returns jsonv1.Number(b). |
| 41 | RawNumberOf func(b []byte) any |
| 42 | ) |