jsonio

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2018 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(r io.Reader, v interface{}) error

Decode a JSON value from a readable. Can decode JSON object and arrays into slices and plain Go values.

If the decoding cannot happen, an error is returned. Otherwise, the value is written straight into v.

func Encode

func Encode(w WriteSeekerTruncater, v interface{}) error

Encode a JSON value to a writer. The encoding is tailored towards jump JSON file needs. Every write truncates the writable and seeks it to it's beginning, so you can safely decode and encode without manipulating the writable.

Technically, the writable needs to implement WriterSeekerTruncater, but you'll most likely use an os.File.

Types

type Truncater

type Truncater interface {
	Truncate(int64) error
}

Truncater encapsulates everything that responds to Truncate(int64).

type WriteSeekerTruncater

type WriteSeekerTruncater interface {
	io.WriteSeeker
	Truncater
}

WriteSeekerTruncater is the interface needed by the Encode first argument. It's a narrower type than a file, and can be more easily mocked in testing.

Jump to

Keyboard shortcuts

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