ju

package module
v0.0.0-...-69e2c6d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2018 License: BSD-3-Clause Imports: 12 Imported by: 3

README

Package ju

Package ju (jason utilities) is a collection of functions to manipulate json objects.

Download

go get -u github.com/akualab/ju

Documentation

http://godoc.org/github.com/akualab/ju

Documentation

Overview

Package ju provides utilities for manipulating json objects.

Index

Constants

This section is empty.

Variables

View Source
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

func ReadJSON(r io.Reader, o interface{}) error

ReadJSON unmarshals json data from an io.Reader. The param "o" must be a pointer to an object.

func ReadJSONFile

func ReadJSONFile(fn string, o interface{}) error

ReadJSONFile unmarshals json data from a file.

func ReadJSONParallel

func ReadJSONParallel(path string, obj interface{}, objCh chan interface{}, numWorkers int)

ReadJSONParallel creates a new streamer to read json objects. See FileStreamer to specify the path. Run it on a seprate goroutine.

func WriteJSON

func WriteJSON(w io.Writer, o interface{}) error

WriteJSON writes an object to an io.Writer.

func WriteJSONFile

func WriteJSONFile(fn string, o interface{}) error

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.

func (*GZIPReader) Read

func (g *GZIPReader) Read(p []byte) (int, error)

Read implements the io.Read interface.

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.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer writes json objects.

func NewWriter

func NewWriter(path string) (*Writer, error)

NewWriter writes graphs to files. path is the filename, if the ext is "gz", the data is gzipped.

func (*Writer) Close

func (w *Writer) Close() error

Close closes the writer.

func (*Writer) Write

func (w *Writer) Write(o interface{}) error

WriteJSON writes a json object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL