[ANN] peanut - write tagged structs to disk, in a variety of formats

167 views
Skip to first unread message

Jim Smart

unread,
Apr 20, 2021, 4:49:04 PM4/20/21
to golang-nuts
Hi there fellow Go Nuts and Gophers,

Whilst working on a project not long back, I created a library to easily write tagged structs to disk, in a variety of output formats.

https://github.com/jimsmart/peanut

Each writer has a simple Write method, that takes a tagged struct. Each type of struct is written to a separate file (or table), with header/field/column names based upon the field tags. All writers use the same tags.

Currently peanut has writers for CSV/TSV, Excel (.xlsx), JSONL, and SQLite — all of which share the same simple interface.

One of the benefits of peanut is that, during development, one can just focus on shape of the data records one is working with (and their population), and not have to think about updating the code that writes the data at all.

Another benefit is that one can easily switch output formats, or indeed support multiple output formats.

It's also handy if one wishes to e.g. output an Excel file report for management, summarising stats and metadata, at the end of a running task (aside from other exported data).

— Maybe this is useful to someone here?

Regards,
/Jim


Jim Smart

unread,
Apr 20, 2021, 5:05:52 PM4/20/21
to golang-nuts
Oh — it also has a few writers that can be helpful during development and testing: swap the file writers for a log writer (or discard writer) during development (handy if your program usually spits out a lot of output files), and swap in the mock writer for easy testing.

/J

cisgo io

unread,
Apr 21, 2021, 12:44:12 PM4/21/21
to golang-nuts
thanks Jim, your effort is really powerful and will find good use.
kg,  Scottie

Ingo Oeser

unread,
Apr 22, 2021, 6:53:21 PM4/22/21
to golang-nuts
A truly fantastic package idea! Thanks a lot for sharing it. 

I just wish it would be cut a little bit differently. 

1 module for the formats using only the stdlib 
1 module each for sqlite and excel support. 

That woukd allow better control over dependencies 
and allow me to avoid the cgo dependency, if I don't need sqlite support. 

On Tuesday, April 20, 2021 at 10:49:04 PM UTC+2 Jim Smart wrote:
Reply all
Reply to author
Forward
0 new messages