fieldmaskutil

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter(msg proto.Message, paths []string)

Filter keeps the msg fields that are listed in the paths and clears all the rest.

This is a handy wrapper for NestedMask.Filter method. If the same paths are used to process multiple proto messages use NestedMask.Filter method directly.

func NilValuePaths added in v1.1.8

func NilValuePaths(msg proto.Message, paths []string) []string

func Overwrite

func Overwrite(src, dest proto.Message, paths []string)

Overwrite overwrites all the fields listed in paths in the dest msg using values from src msg.

This is a handy wrapper for NestedMask.Overwrite method. If the same paths are used to process multiple proto messages use NestedMask.Overwrite method directly.

func Prune

func Prune(msg proto.Message, paths []string)

Prune clears all the fields listed in paths from the given msg.

This is a handy wrapper for NestedMask.Prune method. If the same paths are used to process multiple proto messages use NestedMask.Filter method directly.

Types

type NestedMask

type NestedMask map[string]NestedMask

NestedMask represents a field mask as a recursive map.

func NestedMaskFromPaths

func NestedMaskFromPaths(paths []string) NestedMask

NestedMaskFromPaths creates an instance of NestedMask for the given paths.

func (NestedMask) Filter

func (mask NestedMask) Filter(msg proto.Message)

Filter keeps the msg fields that are listed in the paths and clears all the rest.

If the mask is empty then all the fields are kept. Paths are assumed to be valid and normalized otherwise the function may panic. See google.golang.org/protobuf/types/known/fieldmaskpb for details.

func (NestedMask) Overwrite

func (mask NestedMask) Overwrite(src, dest proto.Message)

Overwrite overwrites all the fields listed in paths in the dest msg using values from src msg.

All other fields are kept untouched. If the mask is empty, no fields are overwritten. Supports scalars, messages, repeated fields, and maps. If the parent of the field is nil message, the parent is initiated before overwriting the field If the field in src is empty value, the field in dest is cleared. Paths are assumed to be valid and normalized otherwise the function may panic.

func (NestedMask) Prune

func (mask NestedMask) Prune(msg proto.Message)

Prune clears all the fields listed in paths from the given msg.

All other fields are kept untouched. If the mask is empty no fields are cleared. This operation is the opposite of NestedMask.Filter. Paths are assumed to be valid and normalized otherwise the function may panic. See google.golang.org/protobuf/types/known/fieldmaskpb for details.

Jump to

Keyboard shortcuts

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