// Keeps the fields mentioned in the paths untouched, all the other fields will be cleared.
fmutils.Filter(protoMessage, []string{"a.b.c", "d"})
// Clears all the fields mentioned in the paths, all the other fields will be left untouched.
fmutils.Prune(protoMessage, []string{"a.b.c", "d"})
// Overwrites the fields in the dst from src.
// Only the fields listed in the field mask will be copied.
fmutils.Overwrite(src, dst, []string{"a.b.c", "d"})
This library uses the new Go API for protocol buffers.
If your *.pb.go
files are generated with the old version APIv1 then you have 2 choices:
google.golang.org/protobuf
github.com/golang/protobuf@v1.4.0
that implements the new APIIn both cases you'll need to regenerate *.pb.go
files.
If you decide to stay with APIv1 then you need to use
the proto.MessageV2
function like this:
import protov1 "github.com/golang/protobuf/proto"
fmutils.Filter(protov1.MessageV2(protoMessage), []string{"a.b.c", "d"})
Read more about the Go protobuf API versions.
See the examples_test.go for real life examples.