proptools

package
v0.0.0-...-41a4f88 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2016 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

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 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 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

func Bool(b *bool) bool

Bool takes a pointer to a bool and returns true iff the pointer is non-nil and points to a true value.

func BoolPtr

func BoolPtr(b bool) *bool

BoolPtr returns a pointer to a new bool containing the given value.

func CloneEmptyProperties

func CloneEmptyProperties(structValue reflect.Value) reflect.Value

func CloneProperties

func CloneProperties(structValue reflect.Value) reflect.Value

func CopyProperties

func CopyProperties(dstValue, srcValue reflect.Value)

func FieldNameForProperty

func FieldNameForProperty(propertyName string) string

func HasTag

func HasTag(field reflect.StructField, name, value string) bool

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 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 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 PropertyNameForField

func PropertyNameForField(fieldName string) string

func String

func String(s *string) 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 StringPtr

func StringPtr(s string) *string

StringPtr returns a pointer to a new string containing the given value.

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 ZeroProperties

func ZeroProperties(structValue reflect.Value)

Types

type ExtendPropertyError

type ExtendPropertyError struct {
	Err      error
	Property string
}

func (*ExtendPropertyError) Error

func (e *ExtendPropertyError) Error() string

type ExtendPropertyFilterFunc

type ExtendPropertyFilterFunc func(property string,
	dstField, srcField reflect.StructField,
	dstValue, srcValue interface{}) (bool, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL