jsonutil

package
v0.0.0-...-b87361e Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadDataFromCompressedJSON

func LoadDataFromCompressedJSON(dataReader io.Reader, v interface{}) error

LoadDataFromCompressedJSON converts the reader into a gzip.Reader and passes it to LoadDataFromJSON. Only closes the gzipReader, not the dataReader. Only returns errors of type jsonutil.JSONError.

func LoadDataFromCompressedJSONFile

func LoadDataFromCompressedJSONFile(path string, v interface{}) error

LoadDataFromCompressedJSONFile loads the content of a file specified by path and passes the file to LoadDataFromCompressedJSON. Makes path absolute. Closes all Readers. Only returns errors of type jsonutil.JSONError.

func LoadDataFromJSON

func LoadDataFromJSON(dataReader io.Reader, v interface{}) error

LoadDataFromJSON uses ioutil.ReadAll to read the byte slice from dataReader and passes the slice to json.Unmarshal. It does not close the dataReader. Only returns errors of type jsonutil.JSONError.

func LoadDataFromJSONFile

func LoadDataFromJSONFile(path string, v interface{}) error

LoadDataFromJSONFile loads the content of a file specified by path. Makes path absolute Content is loaded into v. Returns a JSONError on failure.

func StoreDataToCompressedJSON

func StoreDataToCompressedJSON(v interface{}, compressionLevel int) ([]byte, error)

StoreDataToCompressedJSON passes v to StoreDataToJSON. The JSON is then compressed into a buffer and buf.Bytes() is returned. Only returns errors of type jsonutil.JSONError.

func StoreDataToCompressedJSONFile

func StoreDataToCompressedJSONFile(path string, v interface{}, overwrite bool, compressionLevel int) error

StoreDataToCompressedJSONFile converts the content of v into JSON if possible, compresses the byte slice using compressionLevel (gzip.constants) and stores the content into a file at path. Makes path absolute. If path already exists and the overwrite flag is not set, an error is returned.

func StoreDataToJSON

func StoreDataToJSON(v interface{}) ([]byte, error)

StoreDataToJSON is the same as json.Marshal but only returns errors of type jsonutil.JSONError.

func StoreDataToJSONFile

func StoreDataToJSONFile(path string, v interface{}, overwrite bool) error

StoreDataToJSONFile converts the content of v into JSON if possible and stores the content into a file at path. Makes path absolute. If path already exists and the overwrite flag is not set, an error is returned.

Types

type JSONError

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

JSONError is either a Load Or a Store Error. it capsulates the underlying error.

func (*JSONError) Error

func (s *JSONError) Error() string

Jump to

Keyboard shortcuts

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