Documentation ¶
Overview ¶
Package maskmerge deals with merging protocol buffer messages using field masks.
See google.golang.org/protobuf/types/known/fieldmaskpb for more information on how field masks are interpreted.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MaskMerge ¶
func MaskMerge(dst, src proto.Message, mask *fieldmaskpb.FieldMask) error
MaskMerge merges the fields in mask in src into dst. Following the specification field mask specification, lists and messages are merged, not replaced.
Example ¶
package main import ( "fmt" "log" "github.com/marcusirgens/maskmerge" "github.com/marcusirgens/maskmerge/internal/prototest" "google.golang.org/protobuf/types/known/fieldmaskpb" ) func main() { // Original data to update stored := &prototest.B1{D: 12, X: 15} // New data from the user userData := &prototest.B1{X: 42} // Only update path x mask, err := fieldmaskpb.New(userData, "x") if err != nil { log.Fatalf("invalid field mask: %v", err) } if err := maskmerge.MaskMerge(stored, userData, mask); err != nil { log.Fatalf("merging messages: %v", err) } // not using prototext because the output is not stable. fmt.Printf("d:%d x:%d", stored.D, stored.X) }
Output: d:12 x:42
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.