Documentation
¶
Overview ¶
Package json provides JSON-related utilities for ToolHive.
This package extends Go's standard json package with types that work seamlessly with both Kubernetes CRDs and CLI YAML configurations.
Index ¶
- type Any
- type Data
- func (d *Data[T]) DeepCopy() *Data[T]
- func (d *Data[T]) DeepCopyInto(out *Data[T])
- func (d Data[T]) Get() T
- func (d Data[T]) IsEmpty() bool
- func (d Data[T]) MarshalJSON() ([]byte, error)
- func (d Data[T]) MarshalYAML() (interface{}, error)
- func (d Data[T]) ToAny() (any, error)
- func (d Data[T]) ToMap() (map[string]any, error)
- func (d *Data[T]) UnmarshalJSON(data []byte) error
- func (d *Data[T]) UnmarshalYAML(node *yaml.Node) error
- type Map
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Any ¶
Any is a type alias for Data[any], storing arbitrary JSON values. This is the most flexible type, suitable when the JSON structure is unknown.
+kubebuilder:pruning:PreserveUnknownFields +kubebuilder:validation:Type=object
func FromRawExtension ¶
func FromRawExtension(ext runtime.RawExtension) (Any, error)
FromRawExtension creates an Any from runtime.RawExtension. Returns an error if the JSON cannot be unmarshaled.
type Data ¶
type Data[T any] struct { // Value holds the typed Go value. Value T `json:"-" yaml:"-"` }
Data stores JSON-compatible data of type T. It supports both JSON and YAML marshaling/unmarshaling, making it suitable for use in both Kubernetes CRDs and CLI YAML configurations.
The Value field stores the Go value directly, which simplifies usage in tests and when working with the data programmatically.
Common instantiations:
- Data[any] (aliased as Any) for arbitrary JSON values
- Data[map[string]any] (aliased as Map) for JSON objects
+kubebuilder:pruning:PreserveUnknownFields +kubebuilder:validation:Type=object
func (*Data[T]) DeepCopyInto ¶
DeepCopyInto copies the receiver into out. Required for controller-gen.
func (Data[T]) IsEmpty ¶
IsEmpty returns true if the value is nil or empty. For maps and slices, it checks if the length is 0.
func (Data[T]) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Data[T]) MarshalYAML ¶
MarshalYAML implements yaml.Marshaler.
func (Data[T]) ToAny ¶
ToAny returns the data as any type. This is useful when you need to pass the value to functions expecting any.
func (Data[T]) ToMap ¶
ToMap returns the data as a map[string]any. This is a convenience method for Any types. Returns nil if there is no data or if the data is not a map.
func (*Data[T]) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Map ¶
Map is a type alias for Data[map[string]any], storing JSON objects. Use this when you know the data will always be a JSON object (not array, string, etc.).
+kubebuilder:pruning:PreserveUnknownFields +kubebuilder:validation:Type=object
func MapFromRawExtension ¶
func MapFromRawExtension(ext runtime.RawExtension) (Map, error)
MapFromRawExtension creates a Map from runtime.RawExtension. Returns an error if the JSON cannot be unmarshaled.