Documentation ¶
Overview ¶
Package ju provides utilities for manipulating json objects.
Index ¶
- Variables
- func FileStreamer(path string, ext ...string) (io.ReadCloser, error)
- func ReadJSON(r io.Reader, o interface{}) error
- func ReadJSONFile(fn string, o interface{}) error
- func ReadJSONParallel(path string, obj interface{}, objCh chan interface{}, numWorkers int)
- func WriteJSON(w io.Writer, o interface{}) error
- func WriteJSONFile(fn string, o interface{}) error
- type GZIPReader
- type JSONStreamer
- type Writer
Constants ¶
This section is empty.
Variables ¶
var Done = errors.New("no more json objects")
Done is returned as the error value when there are no more objects to process.
Functions ¶
func FileStreamer ¶
func FileStreamer(path string, ext ...string) (io.ReadCloser, error)
FileStreamer returns a reader that streams data from multiple files. The list of files can be specified in multiple ways: (1) path is a single file. The file may be gzipped in which case the name extension must be ".gz". (2) path is a directory. Reads from all the files in that directory such that (a) the filename must not start with a period, (b) the filename has extension ".gz", (c) the "ext" parameter is empty or the allowed extensions are listed, (d) path is not a symboic link. (3) path is a file with extension ".list" that contains a list of paths to files. Read from all the files in the list.
The return value is of type io.ReadCloser. It is the caller's responsibility to call Close on the ReadCloser when done.
func ReadJSON ¶
ReadJSON unmarshals json data from an io.Reader. The param "o" must be a pointer to an object.
func ReadJSONFile ¶
ReadJSONFile unmarshals json data from a file.
func ReadJSONParallel ¶
ReadJSONParallel creates a new streamer to read json objects. See FileStreamer to specify the path. Run it on a seprate goroutine.
func WriteJSONFile ¶
WriteJSONFile writes to a file.
Types ¶
type GZIPReader ¶
type GZIPReader struct {
// contains filtered or unexported fields
}
GZIPReader is a wrapper to read compressed gzip files.
func NewGZIPReader ¶
func NewGZIPReader(r io.ReadCloser) (*GZIPReader, error)
NewGZIPReader creates a new GZIPReader that reads from r. The return value implements io.ReadCloser. It is the caller's responsibility to call Close when done.
func (*GZIPReader) Close ¶
func (g *GZIPReader) Close() error
Close closes the gzip reader and the wrapped reader.
type JSONStreamer ¶
type JSONStreamer struct {
// contains filtered or unexported fields
}
JSONStreamer will unmarshal a stream of JSON objects.
func NewJSONStreamer ¶
func NewJSONStreamer(path string) (*JSONStreamer, error)
NewJSONStreamer creates a new streamer to read json objects. See FileStreamer to specify the path.
func (*JSONStreamer) Close ¶
func (js *JSONStreamer) Close() error
Close the JSON streamer. Will close the underlyign readers.
func (*JSONStreamer) Next ¶
func (js *JSONStreamer) Next(dst interface{}) error
Next returns the next JSON object. When there are no more results, Done is returned as the error.