Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StructToMap ¶
func StructToMap(filter FieldFilter, src interface{}, dst map[string]interface{}) error
StructToMap copies `src` struct to the `dst` map. Behavior is similar to `StructToStruct`. Arrays in the non-empty dst are converted to slices.
func StructToStruct ¶
func StructToStruct(filter FieldFilter, src, dst interface{}) error
StructToStruct copies `src` struct to `dst` struct using the given FieldFilter. Only the fields where FieldFilter returns true will be copied to `dst`. `src` and `dst` must be coherent in terms of the field names, but it is not required for them to be of the same type. Unexported fields are copied only if the corresponding struct filter is empty and `dst` is assignable to `src`.
Types ¶
type FieldFilter ¶
type FieldFilter interface { // Filter should return a corresponding FieldFilter for the given fieldName and a boolean result. If result is true // then the field is copied, skipped otherwise. Filter(fieldName string) (FieldFilter, bool) // Returns true if the FieldFilter is empty. In this case all fields are copied. IsEmpty() bool }
FieldFilter is an interface used by the copying function to filter fields that are needed to be copied.
type FieldFilterContainer ¶
type FieldFilterContainer interface { FieldFilter // Get gets the FieldFilter for the given field name. Result is false if the filter is not found. Get(fieldName string) (filter FieldFilterContainer, result bool) // Set sets the FieldFilter for the given field name. Set(fieldName string, filter FieldFilterContainer) }
FieldFilterContainer is a FieldFilter with additional methods Get and Set.
func FieldFilterFromPaths ¶
func FieldFilterFromPaths(paths []string, naming func(string) string, filter func() FieldFilterContainer) (FieldFilterContainer, error)
FieldFilterFromPaths creates a new FieldFilter from the given paths.
func FieldFilterFromString ¶
func FieldFilterFromString(input string, filter func() FieldFilterContainer) FieldFilterContainer
FieldFilterFromString creates a new FieldFilterContainer from string. Input string is supposed to be a valid string representation of a FieldFilter like "a,b,c{d,e{f,g}},d". Use it in tests only as the input string is not validated and the underlying function panics in case of a parse error.
type Mask ¶
type Mask map[string]FieldFilterContainer
Mask is a tree-based implementation of a FieldFilter.
func MaskFromPaths ¶
MaskFromPaths creates a new Mask from the given paths.
func MaskFromProtoFieldMask ¶
MaskFromProtoFieldMask creates a Mask from the given FieldMask.
func MaskFromString ¶
MaskFromString creates a new Mask instance from a given string. Use in tests only. See FieldFilterFromString for details.
func (Mask) Filter ¶
func (m Mask) Filter(fieldName string) (FieldFilter, bool)
Filter returns true for those fieldNames that exist in the underlying map. Field names that start with "XXX_" are ignored as unexported.
func (Mask) Get ¶
func (m Mask) Get(fieldName string) (FieldFilterContainer, bool)
Get gets the FieldFilter for the given field name. Result is false if the filter is not found.
func (Mask) Set ¶
func (m Mask) Set(fieldName string, filter FieldFilterContainer)
Set sets the FieldFilter for the given field name.
type MaskInverse ¶
type MaskInverse map[string]FieldFilterContainer
MaskInverse is an inversed version of a Mask (will copy all the fields except those mentioned in the mask).
func MaskInverseFromPaths ¶
func MaskInverseFromPaths(paths []string, naming func(string) string) (MaskInverse, error)
MaskInverseFromPaths creates a new MaskInverse from the given paths.
func MaskInverseFromProtoFieldMask ¶
func MaskInverseFromProtoFieldMask(fm *field_mask.FieldMask, naming func(string) string) (MaskInverse, error)
MaskInverseFromProtoFieldMask creates a MaskInverse from the given FieldMask.
func MaskInverseFromString ¶
func MaskInverseFromString(s string) MaskInverse
MaskInverseFromString creates a new MaskInverse instance from a given string. Use in tests only. See FieldFilterFromString for details.
func (MaskInverse) Filter ¶
func (m MaskInverse) Filter(fieldName string) (FieldFilter, bool)
Filter returns true for those fieldNames that do NOT exist in the underlying map. Field names that start with "XXX_" are ignored as unexported.
func (MaskInverse) Get ¶
func (m MaskInverse) Get(fieldName string) (FieldFilterContainer, bool)
Get gets the FieldFilter for the given field name. Result is false if the filter is not found.
func (MaskInverse) IsEmpty ¶
func (m MaskInverse) IsEmpty() bool
IsEmpty returns true if the mask is empty.
func (MaskInverse) Set ¶
func (m MaskInverse) Set(fieldName string, filter FieldFilterContainer)
Set sets the FieldFilter for the given field name.
func (MaskInverse) String ¶
func (m MaskInverse) String() string