encoding

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2017 License: Apache-2.0 Imports: 9 Imported by: 5

Documentation

Overview

YAML and JSON encoding

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorInvalidExtension = errors.New("File extension must be [.json | .yml | .yaml]")
)

Functions

func ConvertFile

func ConvertFile(infile, outfile string, dataType interface{}) error

Types

type Encoder

type Encoder interface {
	MarshalIndent(data interface{}) (string, error)

	Marshal(data interface{}) (string, error)

	UnMarshal(r io.Reader, result interface{}) error

	UnMarshalStr(data string, result interface{}) error
}

func DefaultJSONEncoder added in v0.9.2

func DefaultJSONEncoder() Encoder

func DefaultYAMLEncoder added in v0.9.2

func DefaultYAMLEncoder() Encoder

func NewEncoder

func NewEncoder(encoder EncoderType) (Encoder, error)

func NewEncoderFromFileExt

func NewEncoderFromFileExt(filename string) (Encoder, error)

type EncoderType

type EncoderType int
const (
	JSON EncoderType = 1 + iota
	YAML
)

func EncoderTypeFromExt added in v0.8.9

func EncoderTypeFromExt(filename string) (EncoderType, error)

type JSONEncoder

type JSONEncoder struct{}

An encoder that marshal's and unmarshal's Json which implements the Encoder interface

func (*JSONEncoder) Marshal

func (e *JSONEncoder) Marshal(data interface{}) (string, error)

func (*JSONEncoder) MarshalIndent

func (e *JSONEncoder) MarshalIndent(data interface{}) (string, error)

func (*JSONEncoder) UnMarshal

func (e *JSONEncoder) UnMarshal(r io.Reader, result interface{}) error

func (*JSONEncoder) UnMarshalStr

func (e *JSONEncoder) UnMarshalStr(data string, result interface{}) error

type YAMLEncoder

type YAMLEncoder struct{}

An encoder that marshal's and unmarshal's YAML which implements the Encoder interface

func (*YAMLEncoder) Marshal

func (e *YAMLEncoder) Marshal(data interface{}) (string, error)

func (*YAMLEncoder) MarshalIndent

func (e *YAMLEncoder) MarshalIndent(data interface{}) (string, error)

func (*YAMLEncoder) UnMarshal

func (e *YAMLEncoder) UnMarshal(r io.Reader, result interface{}) error

func (*YAMLEncoder) UnMarshalStr

func (e *YAMLEncoder) UnMarshalStr(data string, result interface{}) error

Jump to

Keyboard shortcuts

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