internal.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. package internal
  5. import "errors"
  6. // NotForPublicUse is a marker type that an API is for internal use only.
  7. // It does not perfectly prevent usage of that API, but helps to restrict usage.
  8. // Anything with this marker is not covered by the Go compatibility agreement.
  9. type NotForPublicUse struct{}
  10. // AllowInternalUse is passed from "json" to "jsontext" to authenticate
  11. // that the caller can have access to internal functionality.
  12. var AllowInternalUse NotForPublicUse
  13. // Sentinel error values internally shared between jsonv1 and jsonv2.
  14. var (
  15. ErrCycle = errors.New("encountered a cycle")
  16. ErrNonNilReference = errors.New("value must be passed as a non-nil pointer reference")
  17. )
  18. var (
  19. // TransformMarshalError converts a v2 error into a v1 error.
  20. // It is called only at the top-level of a Marshal function.
  21. TransformMarshalError func(any, error) error
  22. // NewMarshalerError constructs a jsonv1.MarshalerError.
  23. // It is called after a user-defined Marshal method/function fails.
  24. NewMarshalerError func(any, error, string) error
  25. // TransformUnmarshalError converts a v2 error into a v1 error.
  26. // It is called only at the top-level of a Unmarshal function.
  27. TransformUnmarshalError func(any, error) error
  28. // NewRawNumber returns new(jsonv1.Number).
  29. NewRawNumber func() any
  30. // RawNumberOf returns jsonv1.Number(b).
  31. RawNumberOf func(b []byte) any
  32. )