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 ¶
- Variables
- type Extensions
- func (e Extensions) Clone() Extensions
- func (e Extensions) Decode[T any](key string) (T, bool, error)
- func (e Extensions) Equal(other Extensions) bool
- func (e Extensions) IsZero() bool
- func (e Extensions) MarshalJSON() ([]byte, error)
- func (e *Extensions) Merge(source Extensions) error
- func (e *Extensions) Set(key string, value any) error
- func (e *Extensions) UnmarshalJSON(data []byte) error
- func (e Extensions) Validate() error
- type Map
- func (m Map) Clone() Map
- func (m Map) Decode[T any](key string) (T, bool, error)
- func (m Map) Equal(other Map) bool
- func (m Map) IsZero() bool
- func (m Map) MarshalJSON() ([]byte, error)
- func (m *Map) Merge(source Map) error
- func (m *Map) Set(key string, value any) error
- func (m *Map) UnmarshalJSON(data []byte) error
- func (m Map) Validate() error
- func (m Map) Values() (map[string]any, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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) 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) 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 ¶
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.