patchstruct

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PatchBytes

func PatchBytes(dst, src []byte) ([]byte, error)

PatchBytes follows the same rules as above with PatchStruct, but instead of patching structpb.Structs, it patches the protobuf encoding. An error is returned if there are issues working with the data. If src is nil or empty, the result is a marshaled, empty struct.

func PatchStruct

func PatchStruct(dst, src *structpb.Struct) *structpb.Struct

PatchStruct updates the struct found in dst with the values found in src. The intent of this helper is to provide a fallback mechanism for subtype attributes when the actual schema of the subtype attributes are unknown. As such, it's preferred to use other methods (such as mask mapping) when an actual message for the subtype is known.

The following rules apply:

* The source (src) map is merged into the destination map (dst). If the source map is nil, the destination will be a valid, but empty, map.

* Values are overwritten by the source map if they exist in both.

  • Values are deleted from the destination if they are set to null in the source.
  • Maps are recursively applied, meaning that a nested map at key "foo" in the destination would be patched with a map at key "foo" in the source.
  • A map in the destination is overwritten by a non-map in the source, and a non-map in the destination is overwritten by a map in the source.

PatchStruct returns the updated map as a copy, dst and src are not altered.

Types

This section is empty.

Jump to

Keyboard shortcuts

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