Open tv42 opened 10 years ago
And an example of OGDL paths in struct tag would be something like
noise
goodstuff 42
type T struct {
Value int `ogdl:"noise.goodstuff"`
}
Your wish is totally justified. Hǎiliàng Wang has started working in that direction.
I wish I had an OGDL library that looked like everything else under encoding/*.
Yes, it'll lose information, and can't round-trip all OGDL data. But it's way more convenient to use than needing to run "queries" on a thing on every access, or writing a function that runs all those queries and returns a struct with the results..
Think of it as ogdl.Graph being the moral equivalent of decoding JSON to interface{}. Used when you know you need to round-trip, but otherwise painful.
It could use struct tags in a way vary similar to encoding/xml, and allow the user to put ogdl paths in them. Something like
And naturally each field would use encoding/text to actually parse the string. And if the value isn't a string but a subgraph, you could see if the field has a UnmarshalOGDL / MarshalOGDL method, just like JSON; the input to such unmarshal would be a Graph, not []byte.
Even more ideally, this would tie into a streaming parser and avoid holding the graph in memory all at once. And the above UnmarshalOGDL could tie into EventHandler or Parser somehow, too.