Documentation
¶
Index ¶
- func Filter(msg proto.Message, paths []string)
- func FilterByFieldMask(msg *proto.Message, fm *fieldmaskpb.FieldMask) error
- func NilValuePaths(msg proto.Message, paths []string) []string
- func NormalizeFieldMaskPaths(fm *fieldmaskpb.FieldMask)
- func NormalizePaths(paths []string) []string
- func Overwrite(src, dest proto.Message, paths []string)
- func OverwriteByFieldMask(msg *proto.Message, fm *fieldmaskpb.FieldMask) error
- func PathsFromFieldNumbers(msg proto.Message, fieldNumbers ...int) []string
- func Prune(msg proto.Message, paths []string)
- func PruneByFieldMask(msg *proto.Message, fm *fieldmaskpb.FieldMask) error
- func Validate(validationModel proto.Message, paths []string) error
- func ValidateFieldMask(msg proto.Message, fm *fieldmaskpb.FieldMask) error
- type NestedMask
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Filter ¶
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 FilterByFieldMask ¶
func FilterByFieldMask(msg *proto.Message, fm *fieldmaskpb.FieldMask) error
FilterByFieldMask keeps the msg fields that are listed in the given FieldMask and clears all the rest.
func NormalizeFieldMaskPaths ¶
func NormalizeFieldMaskPaths(fm *fieldmaskpb.FieldMask)
NormalizeFieldMaskPaths normalizes the paths in the given FieldMask to snake_case
func NormalizePaths ¶
func Overwrite ¶
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 OverwriteByFieldMask ¶
func OverwriteByFieldMask(msg *proto.Message, fm *fieldmaskpb.FieldMask) error
OverwriteByFieldMask overwrites all the fields listed in the given FieldMask in the dest msg using values from src msg.
func PathsFromFieldNumbers ¶
PathsFromFieldNumbers converts protobuf field numbers to field paths for the given message.
This function takes a protobuf message and a list of field numbers, and returns a slice of field paths (field names) corresponding to those numbers.
Field numbers that don't exist in the message descriptor are skipped.
If no field numbers are provided, returns nil.
Example:
// For a message with fields: name (field 1), age (field 2), address (field 3) paths := PathsFromFieldNumbers(msg, 1, 2) // Returns: ["name", "age"]
func Prune ¶
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.
func PruneByFieldMask ¶
func PruneByFieldMask(msg *proto.Message, fm *fieldmaskpb.FieldMask) error
PruneByFieldMask clears all the fields listed in the given FieldMask from the msg.
func Validate ¶
Validate checks if all paths are valid for specified message
This is a handy wrapper for NestedMask.Validate method. If the same paths are used to process multiple proto messages use NestedMask.Validate method directly.
func ValidateFieldMask ¶
func ValidateFieldMask(msg proto.Message, fm *fieldmaskpb.FieldMask) error
ValidateFieldMask checks if all paths in the given FieldMask are valid for the specified message.
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.
For example ["foo.bar", "foo.baz"] becomes {"foo": {"bar": nil, "baz": nil}}.
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.