I'm using protobuf
in Go to send data between microservices, and I have a question about an adapter I'm currently building.
I have protobuf
objects created using protoc
in the target system. Now I have XML files provided by an external party that I want to translate into those protobuf
objects and send them in.
In general when parsing XML in Go, you would obviously do something like:
type MyType struct {
MyValue string `xml:"my_value,attr"`
}
However, since I already gave the objects, I would like to avoid having to duplicate them all just to have to do something like:
func main() {
mt := mt.Parse()
pbobj.MyValue = mt.MyValue
pbobj.MyOtherValue = mt.MyOtherValue
// and on and on and on
}
What is the best way to handle this? Should I create duplicate objects and map them, or can I just apply some kind of XML-tag mapper to the already-existing objects created from protoc
?
Thanks.