format

package
v2.2.6 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: BSD-3-Clause Imports: 2 Imported by: 2

Documentation

Overview

Package format provides a registry and interfaces for output formatters.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrFormat is the base error for formatter failures.
	ErrFormat = fmt.Errorf("format error")
	// ErrNoSerializer indicates a payload does not implement any supported serializer.
	ErrNoSerializer = fmt.Errorf("message is not serializable")
)

Functions

func GetFormats

func GetFormats() []string

GetFormats returns the list of registered formatter names.

func RegisterFormatDriver

func RegisterFormatDriver(name string, t FormatDriver)

RegisterFormatDriver registers and prepares a formatter under a name.

Types

type DriverFormatError

type DriverFormatError struct {
	Driver string
	Err    error
}

DriverFormatError wraps a driver-specific error with its formatter name.

func (*DriverFormatError) Error

func (e *DriverFormatError) Error() string

func (*DriverFormatError) Unwrap

func (e *DriverFormatError) Unwrap() []error

type Format

type Format struct {
	FormatDriver
	// contains filtered or unexported fields
}

Format is a named formatter wrapper used by the registry.

func FindFormat

func FindFormat(name string) (*Format, error)

FindFormat returns a configured formatter by name.

func (*Format) Format

func (t *Format) Format(data interface{}) ([]byte, []byte, error)

Format calls the underlying driver and annotates errors with the driver name.

type FormatDriver

type FormatDriver interface {
	Prepare() error                                  // Prepare driver (eg: flag registration)
	Init() error                                     // Initialize driver (eg: parse keying)
	Format(data interface{}) ([]byte, []byte, error) // Send a message
}

FormatDriver describes a formatter plugin lifecycle and output method.

type FormatInterface

type FormatInterface interface {
	Format(data interface{}) ([]byte, []byte, error)
}

FormatInterface is the minimal interface needed to format payloads.

Directories

Path Synopsis
Package binary implements binary output formatting using encoding.BinaryMarshaler.
Package binary implements binary output formatting using encoding.BinaryMarshaler.
Package json implements JSON output formatting.
Package json implements JSON output formatting.
Package text implements text output formatting.
Package text implements text output formatting.

Jump to

Keyboard shortcuts

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