Documentation
¶
Overview ¶
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 Float
- type Int
- type List
- type Map
- 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) 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)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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.
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 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 (Value) Less ¶
Less provides a total ordering for Value (so that they can be sorted, even if they are of different types).
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.