metadata

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 7 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 is the JSON-only, namespaced provider extension value used by protocol options. It owns both the namespace/name key policy and encoded value ownership, so invalid extension state cannot be constructed through a public map.

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) 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 is the JSON-only extension boundary shared by protocol values. Keeping values encoded prevents runtime objects such as functions, readers, and SDK clients from entering DTOs unnoticed. Its zero value is writable through Set; Clone and Merge copy encoded bytes, and Merge validates both sides before changing the receiver. Equal intentionally compares the encoded form rather than performing semantic JSON normalization.

func FromValues

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

FromValues is the boundary where untyped decoded JSON becomes a validated Map. It exists so provider extensions and stored metadata are checked once on entry rather than trusted and then found unmarshalable at the next hop.

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) 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