load

package
v0.0.0-...-c937b9e Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2015 License: MIT Imports: 8 Imported by: 6

Documentation

Index

Constants

View Source
const JsonFormat = Format("json")
View Source
const TomlFormat = Format("toml")
View Source
const (
	UnknownFormat = Format("")
)
View Source
const YamlFormat = Format("yaml")

Variables

View Source
var DefaultLoader = Loader{
	Loaders: map[Format]LoaderFunc{
		TomlFormat: LoadToml,
		JsonFormat: LoadJson,
		YamlFormat: LoadYaml,
	},
	ExtToFormat: map[string]Format{
		".toml": TomlFormat,
		".tml":  TomlFormat,
		".json": JsonFormat,
		".yaml": YamlFormat,
		".yml":  YamlFormat,
	},
}

Functions

func FromFile

func FromFile(filename string, dst interface{}, opts ...Opts) error

load data to dst struct from file according to format with default loader

func FromReader

func FromReader(r io.Reader, dst interface{}, format Format) error

load data to dst struct from f according to format with default loader

func LoadJson

func LoadJson(r io.Reader, dst interface{}) error

func LoadToml

func LoadToml(r io.Reader, dst interface{}) error

func LoadYaml

func LoadYaml(r io.Reader, dst interface{}) error

Types

type Format

type Format string

type Loader

type Loader struct {
	ExtToFormat map[string]Format
	Loaders     map[Format]LoaderFunc
}

func New

func New() *Loader

func (*Loader) FromFile

func (l *Loader) FromFile(filename string, dst interface{}, opts ...Opts) error

load data to dst struct from file according to format

func (*Loader) FromReader

func (l *Loader) FromReader(r io.Reader, dst interface{}, format Format) error

load data to dst struct from f according to format

type LoaderFunc

type LoaderFunc func(io.Reader, interface{}) error

type Opts

type Opts struct {
	Format Format
}

Jump to

Keyboard shortcuts

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