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 owns namespaced JSON values and prevents unchecked public map mutation.
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 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.