Documentation ¶
Overview ¶
encoding package for YAML and JSON encoding types
Index ¶
- Variables
- func ConvertFile(infile, outfile string, dataType interface{}) error
- type Encoder
- type EncoderType
- type JSONEncoder
- func (e *JSONEncoder) Marshal(data interface{}) (string, error)
- func (e *JSONEncoder) MarshalIndent(data interface{}) (string, error)
- func (e *JSONEncoder) UnMarshal(r io.Reader, result interface{}) error
- func (e *JSONEncoder) UnMarshalFile(f string, v interface{}) error
- func (e *JSONEncoder) UnMarshalStr(data string, result interface{}) error
- type YAMLEncoder
- func (e *YAMLEncoder) Marshal(data interface{}) (string, error)
- func (e *YAMLEncoder) MarshalIndent(data interface{}) (string, error)
- func (e *YAMLEncoder) UnMarshal(r io.Reader, result interface{}) error
- func (e *YAMLEncoder) UnMarshalFile(f string, v interface{}) error
- func (e *YAMLEncoder) UnMarshalStr(data string, result interface{}) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrorInvalidExtension = errors.New("File extension must be [.json | .yml | .yaml]")
Functions ¶
func ConvertFile ¶
ConvertFile converts from one encoding type of infile and writes to another encoding type as the outfile. dataType is the concrete type used for both infile and outfile
Types ¶
type Encoder ¶
type Encoder interface { // MarshalIndent is like Marshal but applies Indent to format the output. MarshalIndent(v interface{}) (string, error) // Marshal returns the JSON or YAML encoding of v. Marshal(v interface{}) (string, error) // Unmarshal parses the JSON-encoded or YAML-encoded data and stores the result in the value pointed to by v. UnMarshal(r io.Reader, v interface{}) error // Unmarshal parses the JSON-encoded or YAML-encoded data and stores the result in the value pointed to by v. UnMarshalFile(f string, v interface{}) error // UnMarshalStr is like UnMarshal but handles a raw string vs. a reader interface UnMarshalStr(data string, result interface{}) error }
func NewEncoder ¶
func NewEncoder(encoder EncoderType) (Encoder, error)
NewEncoder creates an encoder based by the value pointed to by encoder
func NewEncoderFromFileExt ¶
NewEncoderFromFileExt creates an encoder based on the filename extension
type EncoderType ¶
type EncoderType int
Encoder type represents either JSON or YAML
const ( // JSON encoder type JSON EncoderType = 1 + iota // YAML encoder type YAML )
func EncoderTypeFromExt ¶
func EncoderTypeFromExt(filename string) (EncoderType, error)
EncoderTypeFromExt simply returns the encoder type based on the filename extension
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) UnMarshalFile ¶
func (e *JSONEncoder) UnMarshalFile(f string, v 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) UnMarshalFile ¶
func (e *YAMLEncoder) UnMarshalFile(f string, v interface{}) error
func (*YAMLEncoder) UnMarshalStr ¶
func (e *YAMLEncoder) UnMarshalStr(data string, result interface{}) error
Click to show internal directories.
Click to hide internal directories.