Browse Source

add comments

master v0.1.0
Brett Langdon 10 years ago
parent
commit
786e945de5
2 changed files with 11 additions and 0 deletions
  1. +7
    -0
      formatter.go
  2. +4
    -0
      reader.go

+ 7
- 0
formatter.go View File

@ -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 `<key>=<value>` 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)


+ 4
- 0
reader.go View File

@ -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


Loading…
Cancel
Save