structured-merge-diffsigs.k8s.io/structured-merge-diff/value Index | Files

package value

import "sigs.k8s.io/structured-merge-diff/value"

Package value defines types for an in-memory representation of yaml or json objects, organized for convenient comparison with a schema (as defined by the sibling schema package). Functions for reading and writing the objects are also provided.

Index

Types

type Boolean

type Boolean bool

type Field

type Field struct {
	Name  string
	Value Value
}

Field is an individual key-value pair.

type Float

type Float float64

type Int

type Int int64

type List

type List struct {
	Items []Value
}

List is a list of items.

func (*List) Less

func (l *List) Less(rhs *List) bool

Less compares two lists lexically.

type Map

type Map struct {
	Items []Field
	// contains filtered or unexported fields
}

Map is a map of key-value pairs. It represents both structs and maps. We use a list and a go-language map to preserve order.

Set and Get helpers are provided.

func (*Map) Delete

func (m *Map) Delete(key string)

Delete removes the key from the set.

func (*Map) Get

func (m *Map) Get(key string) (*Field, bool)

Get returns the (Field, true) or (nil, false) if it is not present

func (*Map) Less

func (m *Map) Less(rhs *Map) bool

Less compares two maps lexically.

func (*Map) Set

func (m *Map) Set(key string, value Value)

Set inserts or updates the given item.

type String

type String string

type Value

type Value struct {
	// Exactly one of the below must be set.
	FloatValue   *Float
	IntValue     *Int
	StringValue  *String
	BooleanValue *Boolean
	ListValue    *List
	MapValue     *Map
	Null         bool // represents an explicit `"foo" = null`
}

A Value is an object; it corresponds to an 'atom' in the schema.

func BooleanValue

func BooleanValue(b bool) Value

BooleanValue returns b as a scalar boolean Value.

func FloatValue

func FloatValue(f float64) Value

FloatValue returns f as a scalar numeric (float) Value.

func FromJSON

func FromJSON(input []byte) (Value, error)

FromJSON is a helper function for reading a JSON document

func FromJSONFast

func FromJSONFast(input []byte) (Value, error)

FromJSONFast is a helper function for reading a JSON document

func FromUnstructured

func FromUnstructured(in interface{}) (Value, error)

FromUnstructured will convert a go interface to a Value. It's most commonly expected to be used with map[string]interface{} as the input. `in` must not have any structures with cycles in them. yaml.MapSlice may be used for order-preservation.

func FromYAML

func FromYAML(input []byte) (Value, error)

FromYAML is a helper function for reading a YAML document; it attempts to preserve order of keys within maps/structs. This is as a convenience to humans keeping YAML documents, not because there is a behavior difference.

Known bug: objects with top-level arrays don't parse correctly.

func IntValue

func IntValue(i int) Value

IntValue returns i as a scalar numeric (integer) Value.

func ReadJSONIter

func ReadJSONIter(iter *jsoniter.Iterator) (Value, error)

func StringValue

func StringValue(s string) Value

StringValue returns s as a scalar string Value.

func (Value) Equals

func (v Value) Equals(rhs Value) bool

Equals returns true iff the two values are equal.

func (Value) Less

func (v Value) Less(rhs Value) bool

Less provides a total ordering for Value (so that they can be sorted, even if they are of different types).

func (Value) String

func (v Value) String() string

String returns a human-readable representation of the value.

func (*Value) ToJSON

func (v *Value) ToJSON() ([]byte, error)

ToJSON is a helper function for producing a JSon document.

func (*Value) ToJSONFast

func (v *Value) ToJSONFast() ([]byte, error)

ToJSONFast is a helper function for producing a JSon document.

func (*Value) ToUnstructured

func (v *Value) ToUnstructured(preserveOrder bool) interface{}

ToUnstructured will convert the Value into a go-typed object. If preserveOrder is true, then maps will be converted to the yaml.MapSlice type. Otherwise, map[string]interface{} must be used-- this destroys ordering information and is not recommended if the result of this will be serialized. Other types: * list -> []interface{} * others -> corresponding go type, wrapped in an interface{}

Of note, floats and ints will always come out as float64 and int64, respectively.

func (*Value) ToYAML

func (v *Value) ToYAML() ([]byte, error)

ToYAML is a helper function for producing a YAML document; it attempts to preserve order of keys within maps/structs. This is as a convenience to humans keeping YAML documents, not because there is a behavior difference.

func (*Value) WriteJSONStream

func (v *Value) WriteJSONStream(stream *jsoniter.Stream)

Source Files

doc.go fastjson.go unstructured.go value.go

Version
v1.0.0
Published
Aug 17, 2019
Platform
js/wasm
Imports
7 packages
Last checked
6 hours ago

Tools for package owners.