format

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Codecs

func Codecs() map[Format]Codec

Codecs return a list of default codecs.

Types

type Codec

type Codec interface {
	Encoder
	Decoder

	Format() Format
}

Codec takes care of encoding and decoding resources to and from a given format. It writes and reads data to provided io.Writer and io.Reader.

type Decoder

type Decoder interface {
	Decode(src io.Reader, value any) error
}

Decoder decodes values from an io.Reader in a specific format.

type Encoder

type Encoder interface {
	Encode(dst io.Writer, value any) error
}

Encoder encodes values to an io.Writer in a specific format.

type Format

type Format string
const (
	JSON Format = "json"
	YAML Format = "yaml"
)

type JSONCodec

type JSONCodec struct{}

JSONCodec is a Codec that encodes and decodes resources to and from JSON.

func NewJSONCodec

func NewJSONCodec() *JSONCodec

NewJSONCodec returns a new JSONCodec.

func (*JSONCodec) Decode

func (c *JSONCodec) Decode(src io.Reader, value any) error

func (*JSONCodec) Encode

func (c *JSONCodec) Encode(dst io.Writer, value any) error

func (*JSONCodec) Format

func (c *JSONCodec) Format() Format

type YAMLCodec

type YAMLCodec struct {
	BytesAsBase64 bool
}

YAMLCodec is a Codec that encodes and decodes resources to and from YAML.

func NewYAMLCodec

func NewYAMLCodec() *YAMLCodec

NewYAMLCodec returns a new YAMLCodec.

func (*YAMLCodec) Decode

func (c *YAMLCodec) Decode(src io.Reader, value any) error

func (*YAMLCodec) Encode

func (c *YAMLCodec) Encode(dst io.Writer, value any) error

func (*YAMLCodec) Format

func (c *YAMLCodec) Format() Format

Jump to

Keyboard shortcuts

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