Documentation ¶
Index ¶
- func AppendMatchingProperties(dst []interface{}, src interface{}, filter ExtendPropertyFilterFunc) error
- func AppendProperties(dst interface{}, src interface{}, filter ExtendPropertyFilterFunc) error
- func Bool(b *bool) bool
- func BoolDefault(b *bool, def bool) bool
- func BoolPtr(b bool) *bool
- func CloneEmptyProperties(structValue reflect.Value) reflect.Value
- func CloneProperties(structValue reflect.Value) reflect.Value
- func CopyProperties(dstValue, srcValue reflect.Value)
- func ExtendBasicType(dstFieldValue, srcFieldValue reflect.Value, order Order)
- func ExtendMatchingProperties(dst []interface{}, src interface{}, filter ExtendPropertyFilterFunc, ...) error
- func ExtendProperties(dst interface{}, src interface{}, filter ExtendPropertyFilterFunc, ...) error
- func FieldNameForProperty(propertyName string) string
- func FilterPropertyStruct(prop reflect.Type, predicate FilterFieldPredicate) (filteredProp reflect.Type, filtered bool)
- func FilterPropertyStructSharded(prop reflect.Type, maxTypeNameSize int, predicate FilterFieldPredicate) (filteredProp []reflect.Type, filtered bool)
- func HasTag(field reflect.StructField, name, value string) bool
- func Int(i *int64) int
- func Int64Ptr(i int64) *int64
- func IntDefault(i *int64, def int) int
- func NinjaAndShellEscape(s string) string
- func NinjaAndShellEscapeList(slice []string) []string
- func NinjaEscape(s string) string
- func NinjaEscapeList(slice []string) []string
- func PrependMatchingProperties(dst []interface{}, src interface{}, filter ExtendPropertyFilterFunc) error
- func PrependProperties(dst interface{}, src interface{}, filter ExtendPropertyFilterFunc) error
- func PropertyIndexesWithTag(ps interface{}, key, value string) [][]int
- func PropertyNameForField(fieldName string) string
- func ShellEscape(s string) string
- func ShellEscapeList(slice []string) []string
- func String(s *string) string
- func StringDefault(s *string, def string) string
- func StringPtr(s string) *string
- func TypeEqual(s1, s2 interface{}) bool
- func UnpackProperties(properties []*parser.Property, objects ...interface{}) (map[string]*parser.Property, []error)
- func ZeroProperties(structValue reflect.Value)
- type ExtendPropertyError
- type ExtendPropertyFilterFunc
- type ExtendPropertyOrderFunc
- type FilterFieldPredicate
- type Order
- type UnpackError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendMatchingProperties ¶
func AppendMatchingProperties(dst []interface{}, src interface{}, filter ExtendPropertyFilterFunc) error
AppendMatchingProperties appends the values of properties in the property struct src to the property structs in dst. dst and src do not have to be the same type, but every property in src must be found in at least one property in dst. dst must be a slice of pointers to structs, and src must be a pointer to a struct.
The filter function can prevent individual properties from being appended by returning false, or abort AppendProperties with an error by returning an error. Passing nil for filter will append all properties.
An error returned by AppendMatchingProperties that applies to a specific property will be an *ExtendPropertyError, and can have the property name and error extracted from it.
The append operation is defined as appending strings, and slices of strings normally, OR-ing bool values, replacing pointers to booleans or strings whether they are nil or not, and recursing into embedded structs, pointers to structs, and interfaces containing pointers to structs. Appending the zero value of a property will always be a no-op.
func AppendProperties ¶
func AppendProperties(dst interface{}, src interface{}, filter ExtendPropertyFilterFunc) error
AppendProperties appends the values of properties in the property struct src to the property struct dst. dst and src must be the same type, and both must be pointers to structs.
The filter function can prevent individual properties from being appended by returning false, or abort AppendProperties with an error by returning an error. Passing nil for filter will append all properties.
An error returned by AppendProperties that applies to a specific property will be an *ExtendPropertyError, and can have the property name and error extracted from it.
The append operation is defined as appending strings and slices of strings normally, OR-ing bool values, replacing non-nil pointers to booleans or strings, and recursing into embedded structs, pointers to structs, and interfaces containing pointers to structs. Appending the zero value of a property will always be a no-op.
func Bool ¶
Bool takes a pointer to a bool and returns true iff the pointer is non-nil and points to a true value.
func BoolDefault ¶
BoolDefault takes a pointer to a bool and returns the value pointed to by the pointer if it is non-nil, or def if the pointer is nil.
func CloneEmptyProperties ¶
CloneEmptyProperties takes a reflect.Value of a pointer to a struct and returns a reflect.Value of a pointer to a new struct that has the zero values for its fields. It recursively clones struct pointers and interfaces that contain struct pointers.
func CloneProperties ¶
CloneProperties takes a reflect.Value of a pointer to a struct and returns a reflect.Value of a pointer to a new struct that copies of the values for its fields. It recursively clones struct pointers and interfaces that contain struct pointers.
func CopyProperties ¶
CopyProperties takes destination and source reflect.Values of a pointer to structs and returns copies each field from the source into the destination. It recursively copies struct pointers and interfaces that contain struct pointers.
func ExtendBasicType ¶
func ExtendMatchingProperties ¶
func ExtendMatchingProperties(dst []interface{}, src interface{}, filter ExtendPropertyFilterFunc, order ExtendPropertyOrderFunc) error
ExtendMatchingProperties appends or prepends the values of properties in the property struct src to the property structs in dst. dst and src do not have to be the same type, but every property in src must be found in at least one property in dst. dst must be a slice of pointers to structs, and src must be a pointer to a struct.
The filter function can prevent individual properties from being appended or prepended by returning false, or abort ExtendMatchingProperties with an error by returning an error. Passing nil for filter will append or prepend all properties.
The order function is called on each non-filtered property to determine if it should be appended or prepended.
An error returned by ExtendMatchingProperties that applies to a specific property will be an *ExtendPropertyError, and can have the property name and error extracted from it.
The append operation is defined as appending strings, and slices of strings normally, OR-ing bool values, replacing non-nil pointers to booleans or strings, and recursing into embedded structs, pointers to structs, and interfaces containing pointers to structs. Appending or prepending the zero value of a property will always be a no-op.
func ExtendProperties ¶
func ExtendProperties(dst interface{}, src interface{}, filter ExtendPropertyFilterFunc, order ExtendPropertyOrderFunc) error
ExtendProperties appends or prepends the values of properties in the property struct src to the property struct dst. dst and src must be the same type, and both must be pointers to structs.
The filter function can prevent individual properties from being appended or prepended by returning false, or abort ExtendProperties with an error by returning an error. Passing nil for filter will append or prepend all properties.
The order function is called on each non-filtered property to determine if it should be appended or prepended.
An error returned by ExtendProperties that applies to a specific property will be an *ExtendPropertyError, and can have the property name and error extracted from it.
The append operation is defined as appending strings and slices of strings normally, OR-ing bool values, replacing non-nil pointers to booleans or strings, and recursing into embedded structs, pointers to structs, and interfaces containing pointers to structs. Appending or prepending the zero value of a property will always be a no-op.
func FieldNameForProperty ¶
FieldNameForProperty converts the name of a property that might appear in a Blueprints file to the name of a field in property struct by uppercasing the first rune.
func FilterPropertyStruct ¶
func FilterPropertyStruct(prop reflect.Type, predicate FilterFieldPredicate) (filteredProp reflect.Type, filtered bool)
FilterPropertyStruct takes a reflect.Type that is either a struct or a pointer to a struct, and returns a reflect.Type that only contains the fields in the original type for which predicate returns true, and a bool that is true if the new struct type has fewer fields than the original type. If there are no fields in the original type for which predicate returns true it returns nil and true.
func FilterPropertyStructSharded ¶
func FilterPropertyStructSharded(prop reflect.Type, maxTypeNameSize int, predicate FilterFieldPredicate) (filteredProp []reflect.Type, filtered bool)
FilterPropertyStructSharded takes a reflect.Type that is either a sturct or a pointer to a struct, and returns a list of reflect.Type that only contains the fields in the original type for which predicate returns true, and a bool that is true if the new struct type has fewer fields than the original type. If there are no fields in the original type for which predicate returns true it returns nil and true. Each returned struct type will have a maximum of 10 top level fields in it to attempt to avoid hitting the 65535 byte type name length limit in reflect.StructOf (reflect.nameFrom: name too long), although the limit can still be reached with a single struct field with many fields in it.
func HasTag ¶
func HasTag(field reflect.StructField, name, value string) bool
HasTag returns true if a StructField has a tag in the form `name:"foo,value"`.
func Int ¶
Int takes a pointer to an int64 and returns the value pointed to by the pointer cast to int if it is non-nil, or 0 if the pointer is nil.
func IntDefault ¶
IntDefault takes a pointer to an int64 and returns the value pointed to by the pointer cast to int if it is non-nil, or def if the pointer is nil.
func NinjaAndShellEscape ¶
func NinjaAndShellEscapeList ¶
func NinjaEscape ¶
NinjaEscapeList takes a string that may contain characters that are meaningful to ninja ($), and escapes it so it will be passed to bash. It is not necessary on input, output, or dependency names, those are handled by ModuleContext.Build. It is generally required on strings from properties in Blueprint files that are used as Args to ModuleContext.Build. A new slice containing the escaped strings is returned.
func NinjaEscapeList ¶
NinjaEscapeList takes a slice of strings that may contain characters that are meaningful to ninja ($), and escapes each string so they will be passed to bash. It is not necessary on input, output, or dependency names, those are handled by ModuleContext.Build. It is generally required on strings from properties in Blueprint files that are used as Args to ModuleContext.Build. A new slice containing the escaped strings is returned.
func PrependMatchingProperties ¶
func PrependMatchingProperties(dst []interface{}, src interface{}, filter ExtendPropertyFilterFunc) error
PrependMatchingProperties prepends the values of properties in the property struct src to the property structs in dst. dst and src do not have to be the same type, but every property in src must be found in at least one property in dst. dst must be a slice of pointers to structs, and src must be a pointer to a struct.
The filter function can prevent individual properties from being prepended by returning false, or abort PrependProperties with an error by returning an error. Passing nil for filter will prepend all properties.
An error returned by PrependProperties that applies to a specific property will be an *ExtendPropertyError, and can have the property name and error extracted from it.
The prepend operation is defined as prepending strings, and slices of strings normally, OR-ing bool values, replacing nil pointers to booleans or strings, and recursing into embedded structs, pointers to structs, and interfaces containing pointers to structs. Prepending the zero value of a property will always be a no-op.
func PrependProperties ¶
func PrependProperties(dst interface{}, src interface{}, filter ExtendPropertyFilterFunc) error
PrependProperties prepends the values of properties in the property struct src to the property struct dst. dst and src must be the same type, and both must be pointers to structs.
The filter function can prevent individual properties from being prepended by returning false, or abort PrependProperties with an error by returning an error. Passing nil for filter will prepend all properties.
An error returned by PrependProperties that applies to a specific property will be an *ExtendPropertyError, and can have the property name and error extracted from it.
The prepend operation is defined as prepending strings, and slices of strings normally, OR-ing bool values, replacing non-nil pointers to booleans or strings, and recursing into embedded structs, pointers to structs, and interfaces containing pointers to structs. Prepending the zero value of a property will always be a no-op.
func PropertyIndexesWithTag ¶
PropertyIndexesWithTag returns the indexes of all properties (in the form used by reflect.Value.FieldByIndex) that are tagged with the given key and value, including ones found in embedded structs or pointers to structs.
func PropertyNameForField ¶
PropertyNameForField converts the name of a field in property struct to the property name that might appear in a Blueprints file. Since the property struct fields must always be exported to be accessed with reflection and the canonical Blueprints style is lowercased names, it lower cases the first rune in the field name unless the field name contains an uppercase rune after the first rune (which is always uppercase), and no lowercase runes.
func ShellEscape ¶
ShellEscapeList takes string that may contain characters that are meaningful to bash and escapes it if necessary by wrapping it in single quotes, and replacing internal single quotes with '\” (one single quote to end the quoting, a shell-escaped single quote to insert a real single quote, and then a single quote to restarting quoting.
func ShellEscapeList ¶
ShellEscapeList takes a slice of strings that may contain characters that are meaningful to bash and escapes them if necessary by wrapping them in single quotes, and replacing internal single quotes with '\” (one single quote to end the quoting, a shell-escaped single quote to insert a real single quote, and then a single quote to restarting quoting. A new slice containing the escaped strings is returned.
func String ¶
String takes a pointer to a string and returns the value of the string if the pointer is non-nil, or an empty string.
func StringDefault ¶
String takes a pointer to a string and returns the value of the string if the pointer is non-nil, or def if the pointer is nil.
func TypeEqual ¶
func TypeEqual(s1, s2 interface{}) bool
TypeEqual takes two property structs, and returns true if they are of equal type, any embedded pointers to structs or interfaces having matching nilitude, and any interface{} values in any embedded structs, pointers to structs, or interfaces are also of equal type.
func UnpackProperties ¶
func UnpackProperties(properties []*parser.Property, objects ...interface{}) (map[string]*parser.Property, []error)
UnpackProperties populates the list of runtime values ("property structs") from the parsed properties. If a property a.b.c has a value, a field with the matching name in each runtime value is initialized from it. See PropertyNameForField for field and property name matching. For instance, if the input contains
{ foo: "abc", bar: {x: 1},}
and a runtime value being has been declared as
var v struct { Foo string; Bar int }
then v.Foo will be set to "abc" and v.Bar will be set to 1 (cf. unpack_test.go for further examples)
The type of a receiving field has to match the property type, i.e., a bool/int/string field can be set from a property with bool/int/string value, a struct can be set from a map (only the matching fields are set), and an slice can be set from a list. If a field of a runtime value has been already set prior to the UnpackProperties, the new value is appended to it (see somewhat inappropriately named ExtendBasicType). The same property can initialize fields in multiple runtime values. It is an error if any property value was not used to initialize at least one field.
func ZeroProperties ¶
ZeroProperties takes a reflect.Value of a pointer to a struct and replaces all of its fields with zero values, recursing into struct, pointer to struct and interface fields.
Types ¶
type ExtendPropertyError ¶
func (*ExtendPropertyError) Error ¶
func (e *ExtendPropertyError) Error() string
type ExtendPropertyFilterFunc ¶
type ExtendPropertyFilterFunc func(property string, dstField, srcField reflect.StructField, dstValue, srcValue interface{}) (bool, error)
type ExtendPropertyOrderFunc ¶
type ExtendPropertyOrderFunc func(property string, dstField, srcField reflect.StructField, dstValue, srcValue interface{}) (Order, error)
type FilterFieldPredicate ¶
type FilterFieldPredicate func(field reflect.StructField, string string) (bool, reflect.StructField)
type Order ¶
type Order int
func OrderAppend ¶
func OrderAppend(property string, dstField, srcField reflect.StructField, dstValue, srcValue interface{}) (Order, error)
func OrderPrepend ¶
func OrderPrepend(property string, dstField, srcField reflect.StructField, dstValue, srcValue interface{}) (Order, error)
func OrderReplace ¶
func OrderReplace(property string, dstField, srcField reflect.StructField, dstValue, srcValue interface{}) (Order, error)
type UnpackError ¶
func (*UnpackError) Error ¶
func (e *UnpackError) Error() string