rveen / ogdl Goto Github PK
View Code? Open in Web Editor NEWOGDL for Go
License: BSD 2-Clause "Simplified" License
OGDL for Go
License: BSD 2-Clause "Simplified" License
The path parser uses the same byte parser used for OGDL text streams, but OGDL paths should be allowed to be UTF-8 strings. A new parser is needed, or an adaptation of the current one (ReadChar and UnreadChar functions are needed, and those require multibyte temporal storage).
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
network
eth0
ip 192.168.0.10
mask 255.255.255.0
gw 192.168.0.1
hostname crispin
nameserver 8.8.8.8
nameserver 8.8.4.4
type Config struct {
Hostname string
// decoding to a map type knows that the subgraph should be >=2
// levels deep, first level becomes the keys
Network map[string]*Interface
// decoding to a slice value appends every matching subgraph
Nameserver []net.IP
}
type Interface struct {
IP net.IP `ogdl:"ip"`
Netmask net.IP `ogdl:"mask"`
Gateway net.IP `ogdl:"gw"`
}
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.
I'm quite excited about the potential that OGDL has. It might be able to become an elegant but complete data representation of all Go data types. (XML is ugly but JSON lacks enough ability, YAML is also too heavy).
The only format that is able to represent complete Go types is encoding/gob, but it is a binary format. Go just lacks a pretty text format to do it.
If you are interested in my proposal, I'd like to contribute to its implementation.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.