package value
import "sigs.k8s.io/structured-merge-diff/v2/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 ¶
- type Boolean
- type Field
- type FieldList
- func (f FieldList) Compare(rhs FieldList) int
- func (f FieldList) Less(rhs FieldList) bool
- func (f FieldList) Sort()
- type Float
- type Int
- type List
- func (l *List) Compare(rhs *List) int
- func (l *List) Equals(rhs *List) bool
- func (l *List) Less(rhs *List) bool
- type Map
- func (m *Map) Compare(rhs *Map) int
- func (m *Map) Delete(key string)
- func (m *Map) Equals(rhs *Map) bool
- func (m *Map) Get(key string) (*Field, bool)
- func (m *Map) Less(rhs *Map) bool
- func (m *Map) Set(key string, value Value)
- type String
- type Value
- func BooleanValue(b bool) Value
- func FloatValue(f float64) Value
- func FromJSON(input []byte) (Value, error)
- func FromJSONFast(input []byte) (Value, error)
- func FromUnstructured(in interface{}) (Value, error)
- func FromYAML(input []byte) (Value, error)
- func IntValue(i int) Value
- func ReadJSONIter(iter *jsoniter.Iterator) (Value, error)
- func StringValue(s string) Value
- func (v Value) Compare(rhs Value) int
- func (v Value) Equals(rhs Value) bool
- func (v Value) Less(rhs Value) bool
- func (v Value) String() string
- func (v *Value) ToJSON() ([]byte, error)
- func (v *Value) ToJSONFast() ([]byte, error)
- func (v *Value) ToUnstructured(preserveOrder bool) interface{}
- func (v *Value) ToYAML() ([]byte, error)
- func (v *Value) WriteJSONStream(stream *jsoniter.Stream)
Types ¶
type Boolean ¶
type Boolean bool
func (Boolean) Compare ¶
Compare compares booleans. The result will be 0 if b==rhs, -1 if b < rhs, and +1 if b > rhs.
type Field ¶
Field is an individual key-value pair.
type FieldList ¶
type FieldList []Field
FieldList is a list of key-value pairs. Each field is expected to have a different name.
func (FieldList) Compare ¶
Less compares two lists lexically. The result will be 0 if f==rhs, -1 if f < rhs, and +1 if f > rhs.
func (FieldList) Less ¶
Less compares two lists lexically.
func (FieldList) Sort ¶
func (f FieldList) Sort()
Sort sorts the field list by Name.
type Float ¶
type Float float64
func (Float) Compare ¶
Compare compares floats. The result will be 0 if f==rhs, -1 if f < rhs, and +1 if f > rhs.
type Int ¶
type Int int64
func (Int) Compare ¶
Compare compares integers. The result will be 0 if i==rhs, -1 if i < rhs, and +1 if i > rhs.
type List ¶
type List struct { Items []Value }
List is a list of items.
func (*List) Compare ¶
Compare compares two lists lexically. The result will be 0 if l==rhs, -1 if l < rhs, and +1 if l > rhs.
func (*List) Equals ¶
Equals compares two lists lexically.
func (*List) Less ¶
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) Compare ¶
Compare compares two maps lexically.
func (*Map) Delete ¶
Delete removes the key from the set.
func (*Map) Equals ¶
Equals compares two maps lexically.
func (*Map) Get ¶
Get returns the (Field, true) or (nil, false) if it is not present
func (*Map) Less ¶
Less compares two maps lexically.
func (*Map) Set ¶
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 ¶
BooleanValue returns b as a scalar boolean Value.
func FloatValue ¶
FloatValue returns f as a scalar numeric (float) Value.
func FromJSON ¶
FromJSON is a helper function for reading a JSON document
func FromJSONFast ¶
FromJSONFast is a helper function for reading a JSON document
func FromUnstructured ¶
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 ¶
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 ¶
IntValue returns i as a scalar numeric (integer) Value.
func ReadJSONIter ¶
func StringValue ¶
StringValue returns s as a scalar string Value.
func (Value) Compare ¶
Compare provides a total ordering for Value (so that they can be sorted, even if they are of different types). The result will be 0 if v==rhs, -1 if v < rhs, and +1 if v > rhs.
func (Value) Equals ¶
Equals returns true iff the two values are equal.
func (Value) Less ¶
Less provides a total ordering for Value (so that they can be sorted, even if they are of different types).
func (Value) String ¶
String returns a human-readable representation of the value.
func (*Value) ToJSON ¶
ToJSON is a helper function for producing a JSon document.
func (*Value) ToJSONFast ¶
ToJSONFast is a helper function for producing a JSon document.
func (*Value) ToUnstructured ¶
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 ¶
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 ¶
Source Files ¶
doc.go fastjson.go unstructured.go value.go
- Version
- v2.0.1 (latest)
- Published
- Jan 10, 2020
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 2 days ago –
Tools for package owners.