Python Generated Code lists Well Known Types, but there is no equivalent in Go Generated Code. I assume if there was, it would document this package google.golang.org/protobuf/types/known.
Specifically, I was looking for documentation on FieldMask
. While it's completely absent on Go Generated Code, I did find it on go.dev (https://pkg.go.dev/google.golang.org/protobuf/types/known/fieldmaskpb).
Question
The Python implementation of FieldMask provides a MergeMessage
function that merges fields specified in FieldMask
from source to destination. This is really useful in API update operations because you can easily merge 2 proto messages while honoring the FieldMask
:
# get field mask and message from request
updated_message = request.message
field_mask = request.mask
# load original message from database
original_message = read_from_db(request.id)
# source, destination
field_mask.MergeMessage(updated_message, original_message)
# original_message is now updated according to the field mask
Is there an equivalent convenience function in Go? If not, how should proto messages be merged using a FieldMask
? Is there a reference implementation or example I could follow? I couldn't find any use of FieldMask
in grpc-go/examples/.
While there is a proto Merge function, it merges all fields and there is no way to incorporate a FieldMask
to merge only specific fields.