go-ds-crdt icon indicating copy to clipboard operation
go-ds-crdt copied to clipboard

PrintDAG should take either a PrinterFunc or a buffer

Open jsimnz opened this issue 5 years ago • 2 comments

The PrintDAG should take either a PrinterFunc(line string) as an argument, or an io.Writer so you can control what the function prints to. I noticed the comments on the PrintDAG function even mention a printerFunc.

Might be a small niche use-case but as an experimental use of the crdt Datastore I've made an HTTP server that takes a go-datastore interface and exposes a basic API, it would be nice to be able to print the DAG and return it over the API. At the moment my only options are using my own fork that implements one of these two options, or some janky stdout copy/buffer stuff (don't want to do).

Thoughts?

jsimnz avatar Jul 18 '19 04:07 jsimnz

Alternatively the function could just return a string, however, then it would probably need a name change to something like DAGToString().

jsimnz avatar Jul 18 '19 09:07 jsimnz

That function is not really used (I used it mostly for debugging at the beginning). It doesn't even work very well (printing a multi-branched DAG is pretty horrible).

I'm happy changing it to whatever fits your needs. Would you like to make a PR?

hsanjuan avatar Jul 18 '19 12:07 hsanjuan