From 786e945de58b56b112176aed4e4b4ecc11e273f5 Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Sat, 7 Nov 2015 13:31:17 -0500 Subject: [PATCH] add comments --- formatter.go | 7 +++++++ reader.go | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/formatter.go b/formatter.go index 0a79f01..4b4ad59 100644 --- a/formatter.go +++ b/formatter.go @@ -7,24 +7,31 @@ import ( "sort" ) +// FormatType denotes the output formatting types supported by jsonstream type FormatType int const ( + // FormatJSON informs the Formatter to output as a JSON object FormatJSON FormatType = iota + // FormatTSV informs the Formatter to output as a tab separated JSON encoded values FormatTSV + // FormatTSVKey informs the Formatter to output as a tab separated `=` pairs FormatTSVKey ) +// Formatter is used for formatting any data into a byte slice type Formatter struct { format FormatType } +// NewFormatter will create a new Formatter with the designated output format func NewFormatter(format FormatType) *Formatter { return &Formatter{ format: format, } } +// Format the provided data into the output format designated for this Formatter func (formatter *Formatter) Format(data interface{}) (buf []byte, err error) { if formatter.format == FormatJSON { buf, err = formatter.formatJSON(data) diff --git a/reader.go b/reader.go index 616b6ba..8d37233 100644 --- a/reader.go +++ b/reader.go @@ -7,11 +7,14 @@ import ( "io" ) +// Reader is used for reading newline delimited JSON objects from an input io.Reader type Reader struct { buffer *bufio.Reader keys map[string]bool } +// NewReader will create a new Reader from the provided io.Reader and keys +// k, when not an empty slice, will tell the Reader to only include the provided keys from the input JSON object func NewReader(r io.Reader, k []string) *Reader { var keys map[string]bool keys = make(map[string]bool, 0) @@ -40,6 +43,7 @@ func (reader *Reader) processData(data interface{}) (processed map[string]interf return processed, err } +// ReadLine will read the next JSON object from the input io.Reader func (reader *Reader) ReadLine() (data interface{}, err error) { var line []byte var isPrefix bool