miekg/exdns

Splitting q into a library and executable?

JeremyRand opened this issue · 5 comments

The q example is really nice, and I've wanted to use similar logic in a few of my projects (so that my own code can stick to a nice high-level API for DNS queries without re-implementing lots of DNS logic), but unfortunately since all of the q code is in the main package, it can't be used as a library. My initial workaround was just to copy and paste the q code into my own projects and make changes as needed, but this doesn't exactly scale well.

Would a PR be accepted that splits q into a library (which has all the code except for the flag stuff and the stdout/stderr formatting, and renames main() to a public function that accepts the args that are currently handled by global flag variables) and an executable (which has all the flag and stdout/stderr formatting code and adds a simple main() function that calls the library using the flag global variables as args)?

(Alternatively, if a library that's similarly flexible and user-friendly as the q example is already exists, feel free to point me to that -- I looked around and couldn't find one.)

miekg commented

If there are useful bits here they should probably move to https://github.com/miekg/dns/tree/master/dnsutil

What bits are useful?

Basically I'd like an API that's equivalent to the command-line API in q, but as a Go function rather than a command-line tool, with function args instead of command-line flags, and with machine-readable return values instead of stdout/stderr output.

miekg commented

Okay. I guess I'll look into making a library fork of q, then. That's why it's open-source after all. :)

For anyone curious who's running across this issue, I've created a library fork of q. https://github.com/namecoin/qlib Very rough around the edges, but works for my use cases.