formatting

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: BSD-3-Clause Imports: 8 Imported by: 37

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(encoding Encoding, str string) ([]byte, error)

Decode [str] to bytes using the given encoding If [str] is the empty string, returns a nil byte slice and nil error

func Encode

func Encode(encoding Encoding, bytes []byte) (string, error)

Encode bytes to a string using the given encoding format bytes may be nil, in which case it will be treated the same as an empty slice.

func IntFormat

func IntFormat(maxValue int) string

Types

type Encoding

type Encoding uint8

Encoding defines how bytes are converted to a string and vice versa

const (
	// Hex specifies a hex plus 4 byte checksum encoding format
	Hex Encoding = iota
	// HexNC specifies a hex encoding format
	HexNC
	// HexC specifies a hex plus 4 byte checksum encoding format
	HexC
	// JSON specifies the JSON encoding format
	JSON
)

func (Encoding) MarshalJSON

func (enc Encoding) MarshalJSON() ([]byte, error)

func (Encoding) MarshalText added in v1.1.3

func (enc Encoding) MarshalText() ([]byte, error)

MarshalText and UnmarshalText are the encoding's written form, which is the one it has always had: MarshalJSON writes this same word in quotes. It is said here as well because a URL carries text and no JSON. A read served as a GET asks for its encoding with ?encoding=json, and an encoding read as the number its kind is left every such request on Hex, which is what zero is.

func (Encoding) String

func (enc Encoding) String() string

func (*Encoding) UnmarshalJSON

func (enc *Encoding) UnmarshalJSON(b []byte) error

UnmarshalJSON reads the same word, quoted. The mapping is in UnmarshalText and is not written a second time; null is JSON's spelling of an absent field, which leaves the encoding as it was.

func (*Encoding) UnmarshalText added in v1.1.3

func (enc *Encoding) UnmarshalText(text []byte) error

type PrefixedStringer

type PrefixedStringer interface {
	fmt.Stringer

	PrefixedString(prefix string) string
}

PrefixedStringer extends a stringer that adds a prefix

Jump to

Keyboard shortcuts

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