Documentation
¶
Index ¶
- Constants
- func Format(writer io.Writer, formatter Formatter, options ...FormatOption) (n int, err error)
- func FormatString(formatter Formatter, options ...FormatOption) (s string, err error)
- type BlockFormatter
- type BoolFormatter
- type FormatOption
- type Formatter
- type HexBytesFormatter
- type HexdumpFormatter
- type KVFormatter
- type KVOption
- type PrintfFormatter
- type StringFormatter
- type StructFormatter
- type Writer
Constants ¶
const DefaultIndent = " "
Variables ¶
This section is empty.
Functions ¶
func FormatString ¶
func FormatString(formatter Formatter, options ...FormatOption) (s string, err error)
Format a structual data and return the formatted string.
Types ¶
type BlockFormatter ¶
func Block ¶
func Block(items ...Formatter) *BlockFormatter
func Bracket ¶
func Bracket(items ...Formatter) *BlockFormatter
func (*BlockFormatter) StructFormat ¶
func (f *BlockFormatter) StructFormat(w Writer) (n int, err error)
type BoolFormatter ¶
type BoolFormatter bool
func Bool ¶
func Bool(value bool) BoolFormatter
Return a BoolFormatter that just outputs true or false.
func (BoolFormatter) StructFormat ¶
func (f BoolFormatter) StructFormat(w Writer) (n int, err error)
type FormatOption ¶
type FormatOption func(*indentWriter)
func WithIndent ¶
func WithIndent(indent string) FormatOption
Use the provided string for each indent level
type Formatter ¶
type Formatter interface { // Format the structual data and write to the Writer interface. Returns the number of bytes written in `n`. StructFormat(Writer) (n int, err error) }
Implement this interface in your data types to support sturctual formatting.
type HexBytesFormatter ¶
type HexBytesFormatter []byte
func HexBytes ¶
func HexBytes(data []byte) HexBytesFormatter
Return a HexBytesFormatter that formats the bytes data using hex.Encoder.
func (HexBytesFormatter) StructFormat ¶
func (f HexBytesFormatter) StructFormat(w Writer) (n int, err error)
type HexdumpFormatter ¶
type HexdumpFormatter []byte
func Hexdump ¶
func Hexdump(data []byte) HexdumpFormatter
Returns a HexdumpFormatter that format the bytes data using hex.Dumper().
func (HexdumpFormatter) StructFormat ¶
func (f HexdumpFormatter) StructFormat(w Writer) (n int, err error)
type KVFormatter ¶
func KV ¶
func KV(name string, value Formatter, options ...KVOption) *KVFormatter
Return a KVFormatter represents a key-value pair. Oftenly used inside the StructFormatter for form a map like structure.
func (*KVFormatter) StructFormat ¶
func (f *KVFormatter) StructFormat(w Writer) (n int, err error)
type PrintfFormatter ¶
type PrintfFormatter struct { Fmt string Args []interface{} }
func Printf ¶
func Printf(format string, args ...interface{}) *PrintfFormatter
Return a PrintfFormatter that apply Printf template to the arguments and format them as a string.
func (*PrintfFormatter) StructFormat ¶
func (f *PrintfFormatter) StructFormat(w Writer) (n int, err error)
type StringFormatter ¶
type StringFormatter string
func String ¶
func String(s string) StringFormatter
Return a StringFormatter for a string. New lines will be indented according to the current indent level of the formatter.
func (StringFormatter) StructFormat ¶
func (f StringFormatter) StructFormat(w Writer) (n int, err error)
type StructFormatter ¶
func Struct ¶
func Struct(name string, items ...Formatter) *StructFormatter
Return a StructFormatter that has a name and arbitrary number of items.
func (*StructFormatter) StructFormat ¶
func (f *StructFormatter) StructFormat(w Writer) (n int, err error)
type Writer ¶
type Writer interface { io.Writer IndentString() string LineNum() int LineOffset() int NonIndentLineOffset() int IsEmpty() bool // Return a new writer with indent level set to be current // indent level plus levelDelta. If levelDelta is 0, indent // is reset to empty level. Indent(levelDelta int) Writer EmptyCheck(prependIfNotEmpty string) Writer RemoveTrailingNewLines() Writer }