metadata

package
v0.57.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package metadata provides JSON-safe extension values for Core protocol types.

Map stores each entry as validated JSON rather than arbitrary Go objects. Use Set or FromValues at write boundaries and Decode or Values at read boundaries. This prevents callbacks, readers, SDK clients, and other runtime state from entering serializable requests, responses, documents, or media. Values preserves JSON numbers as json.Number; Decode uses the caller's target type and its numeric representation limits.

Example
package main

import (
	"fmt"

	"github.com/Tangerg/scope/core/metadata"
)

func main() {
	values := metadata.Map{}
	if err := values.Set("attempt", 3); err != nil {
		panic(err)
	}
	attempt, found, err := values.Decode[int]("attempt")

	fmt.Println(attempt, found, err)
}
Output:
3 true <nil>

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrNilMap       = errors.New("metadata: nil map")
	ErrEmptyKey     = errors.New("metadata: empty key")
	ErrInvalidValue = errors.New("metadata: invalid JSON value")
)

Functions

This section is empty.

Types

type Extensions

type Extensions struct {
	// contains filtered or unexported fields
}

Extensions owns namespaced JSON values and prevents unchecked public map mutation.

func (Extensions) Clone

func (e Extensions) Clone() Extensions

func (Extensions) Decode

func (e Extensions) Decode[T any](key string) (T, bool, error)

func (Extensions) Equal

func (e Extensions) Equal(other Extensions) bool

func (Extensions) IsZero

func (e Extensions) IsZero() bool

func (Extensions) JSONSchemaModel added in v0.57.0

func (Extensions) JSONSchemaModel() any

func (Extensions) MarshalJSON

func (e Extensions) MarshalJSON() ([]byte, error)

func (*Extensions) Merge

func (e *Extensions) Merge(source Extensions) error

func (*Extensions) Set

func (e *Extensions) Set(key string, value any) error

func (*Extensions) UnmarshalJSON

func (e *Extensions) UnmarshalJSON(data []byte) error

func (Extensions) Validate

func (e Extensions) Validate() error

type Map

type Map map[string]json.RawMessage

Map stores encoded JSON extension values. Its zero value is writable through Set. Clone and Merge copy bytes; Merge validates both sides before mutation. Equal compares encoded forms without semantic normalization. JSON preserves nil as null and an explicitly empty map as an object.

func FromValues

func FromValues(values map[string]any) (Map, error)

func (Map) Clone

func (m Map) Clone() Map

func (Map) Decode

func (m Map) Decode[T any](key string) (T, bool, error)

func (Map) Equal

func (m Map) Equal(other Map) bool

func (Map) IsZero

func (m Map) IsZero() bool

func (Map) JSONSchemaModel added in v0.57.0

func (Map) JSONSchemaModel() any

func (Map) MarshalJSON

func (m Map) MarshalJSON() ([]byte, error)

func (*Map) Merge

func (m *Map) Merge(source Map) error

func (*Map) Set

func (m *Map) Set(key string, value any) error

func (*Map) UnmarshalJSON

func (m *Map) UnmarshalJSON(data []byte) error

func (Map) Validate

func (m Map) Validate() error

func (Map) Values

func (m Map) Values() (map[string]any, error)

Values returns an independently owned JSON value tree. Every number remains a json.Number, including nested values; consumers choose numeric conversions at their typed or provider boundary.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL