...

Package encoding

import "github.com/spf13/viper/internal/encoding"
Overview
Index
Subdirectories

Overview ▾

Constants

const (
    // ErrDecoderNotFound is returned when there is no decoder registered for a format.
    ErrDecoderNotFound = encodingError("decoder not found for this format")

    // ErrDecoderFormatAlreadyRegistered is returned when an decoder is already registered for a format.
    ErrDecoderFormatAlreadyRegistered = encodingError("decoder already registered for this format")
)
const (
    // ErrEncoderNotFound is returned when there is no encoder registered for a format.
    ErrEncoderNotFound = encodingError("encoder not found for this format")

    // ErrEncoderFormatAlreadyRegistered is returned when an encoder is already registered for a format.
    ErrEncoderFormatAlreadyRegistered = encodingError("encoder already registered for this format")
)

type Decoder

Decoder decodes the contents of b into v. It's primarily used for decoding contents of a file into a map[string]any.

type Decoder interface {
    Decode(b []byte, v map[string]any) error
}

type DecoderRegistry

DecoderRegistry can choose an appropriate Decoder based on the provided format.

type DecoderRegistry struct {
    // contains filtered or unexported fields
}

func NewDecoderRegistry

func NewDecoderRegistry() *DecoderRegistry

NewDecoderRegistry returns a new, initialized DecoderRegistry.

func (*DecoderRegistry) Decode

func (e *DecoderRegistry) Decode(format string, b []byte, v map[string]any) error

Decode calls the underlying Decoder based on the format.

func (*DecoderRegistry) RegisterDecoder

func (e *DecoderRegistry) RegisterDecoder(format string, enc Decoder) error

RegisterDecoder registers a Decoder for a format. Registering a Decoder for an already existing format is not supported.

type Encoder

Encoder encodes the contents of v into a byte representation. It's primarily used for encoding a map[string]any into a file format.

type Encoder interface {
    Encode(v map[string]any) ([]byte, error)
}

type EncoderRegistry

EncoderRegistry can choose an appropriate Encoder based on the provided format.

type EncoderRegistry struct {
    // contains filtered or unexported fields
}

func NewEncoderRegistry

func NewEncoderRegistry() *EncoderRegistry

NewEncoderRegistry returns a new, initialized EncoderRegistry.

func (*EncoderRegistry) Encode

func (e *EncoderRegistry) Encode(format string, v map[string]any) ([]byte, error)

func (*EncoderRegistry) RegisterEncoder

func (e *EncoderRegistry) RegisterEncoder(format string, enc Encoder) error

RegisterEncoder registers an Encoder for a format. Registering a Encoder for an already existing format is not supported.

Subdirectories

Name Synopsis
..