format

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DisplayFormatter

type DisplayFormatter interface {
	// Encode converts a raw value to a human-readable string.
	Encode(value any) (string, error)
	// Decode converts a human-readable string back to a raw value.
	Decode(display string) (any, error)
}

DisplayFormatter converts between raw values and human-readable strings.

type FormatRegistry

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

FormatRegistry manages registered display format converters.

func NewDefaultFormatRegistry

func NewDefaultFormatRegistry() *FormatRegistry

NewDefaultFormatRegistry creates a FormatRegistry pre-loaded with the built-in formatters: "ipv4", "mac", and "ipv6".

func NewFormatRegistry

func NewFormatRegistry() *FormatRegistry

NewFormatRegistry creates a new empty FormatRegistry.

func (*FormatRegistry) Get

func (r *FormatRegistry) Get(name string) (DisplayFormatter, error)

Get retrieves a display format converter by name. Returns FormatNotFoundError if the format is not registered.

func (*FormatRegistry) Has

func (r *FormatRegistry) Has(name string) bool

Has checks whether a display format is registered.

func (*FormatRegistry) Register

func (r *FormatRegistry) Register(name string, formatter DisplayFormatter)

Register adds a display format converter to the registry.

type IPv4Formatter

type IPv4Formatter struct{}

IPv4Formatter converts between a 32-bit unsigned integer and a dotted-decimal string such as "192.168.1.1".

func (*IPv4Formatter) Decode

func (f *IPv4Formatter) Decode(display string) (any, error)

Decode converts a dotted-decimal IPv4 string to a uint64 value.

func (*IPv4Formatter) Encode

func (f *IPv4Formatter) Encode(value any) (string, error)

Encode converts a numeric value (uint32, uint64, int, int64, etc.) to a dotted-decimal IPv4 string.

type IPv6Formatter

type IPv6Formatter struct{}

IPv6Formatter converts between a 128-bit value and a colon-separated hex group string such as "2001:0db8:0000:0000:0000:0000:0000:0001".

The Encode method accepts [16]byte, []byte (length 16), *big.Int, or big.Int. The Decode method returns a *big.Int.

func (*IPv6Formatter) Decode

func (f *IPv6Formatter) Decode(display string) (any, error)

Decode converts a colon-separated hex group string to a *big.Int.

func (*IPv6Formatter) Encode

func (f *IPv6Formatter) Encode(value any) (string, error)

Encode converts a 128-bit value to a colon-separated hex group string.

type MACFormatter

type MACFormatter struct{}

MACFormatter converts between a 48-bit integer and a colon-separated hex string such as "aa:bb:cc:dd:ee:ff".

func (*MACFormatter) Decode

func (f *MACFormatter) Decode(display string) (any, error)

Decode converts a colon-separated hex MAC string to a uint64 value.

func (*MACFormatter) Encode

func (f *MACFormatter) Encode(value any) (string, error)

Encode converts a numeric value (48-bit range) to a colon-separated hex MAC string.

Jump to

Keyboard shortcuts

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