formatter

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {
	StandardOutput       io.WriteCloser
	ErrorHandlerCallback func(err error)
}

func (*Base) CheckErr

func (f *Base) CheckErr(err error)

func (*Base) Output

func (f *Base) Output(bytes []byte)

type Formatter

type Formatter interface {
	Serialize(in interface{}) (bytes []byte)
	CheckErr(err error)
}

Formatter defines a formatter for serializing an input object into a byte slice. The Serialize method serializes the input object and returns the resulting byte slice. The CheckErr method handles any error encountered during the serialization process.

func New

func New(options Options,
) (f Formatter)

New creates a new instance of the Formatter interface. It takes an Options struct as input and sets default values for some of the fields if they are not specified. The SerializationFormat field of the Options struct is used to determine which implementation of the Formatter interface to return. If the specified format is not supported, the function will panic.

type Json

type Json struct {
	Base
}

func (*Json) Serialize

func (f *Json) Serialize(in interface{}) (bytes []byte)

type Options

type Options struct {
	SerializationFormat string
	StandardOutput      io.WriteCloser
	ErrorHandler        func(err error)
}

Options defines the options for creating a new Formatter instance.

type Xml

type Xml struct {
	Base
}

func (*Xml) Serialize

func (f *Xml) Serialize(in interface{}) (bytes []byte)

type Yaml

type Yaml struct {
	Base
}

func (*Yaml) Serialize

func (f *Yaml) Serialize(in interface{}) (bytes []byte)

Jump to

Keyboard shortcuts

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