Documentation
¶
Overview ¶
Package mapprint provides functionality to print a map/struct in a formated way.
Index ¶
- func Fprintf(w io.Writer, format string, bindings ...interface{}) (int, error)
- func Printf(format string, bindings ...interface{}) (int, error)
- func Sprintf(format string, bindings ...interface{}) string
- type KeyNotFoundFunc
- type PrintValueFunc
- type Printer
- func (printer *Printer) Fprintf(w io.Writer, format string, bindings ...interface{}) (int, error)
- func (printer *Printer) GetKeyToken() rune
- func (printer *Printer) Printf(format string, bindings ...interface{}) (int, error)
- func (printer *Printer) Sprintf(format string, bindings ...interface{}) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fprintf ¶
Fprintf formats a map/struct according to a format specifier and writes to w. It returns the number of bytes written and any write error encountered. example:
Fprintf(w, "%Key1", map[string]interface{}{
"Key1": "Value1",
})
Types ¶
type KeyNotFoundFunc ¶
type KeyNotFoundFunc func(w io.Writer, printer *Printer, prefix, key []rune, defaultPrinter PrintValueFunc) (int, error)
KeyNotFoundFunc describes the custom function that will be called if a Key was not found.
func DefaultValue ¶
func DefaultValue(defaultValue interface{}) KeyNotFoundFunc
DefaultValue returns a default value.
type PrintValueFunc ¶
type PrintValueFunc func(w io.Writer, printer *Printer, prefix, key []rune, value reflect.Value) (int, error)
PrintValueFunc describes the custom function that will be called to print a reflect.Value.
type Printer ¶
type Printer struct {
// KeyToken specifies how keys start
// the Default value is % (percent sign)
KeyToken rune
DefaultBindings interface{}
KeyNotFound KeyNotFoundFunc
PrintValue PrintValueFunc
// SuppressErrors if possible
SuppressErrors bool
// contains filtered or unexported fields
}
Printer is a object that can be used to initialize the printer with custom settings A typical example could be:
p := Printer{
KeyToken: '$',
KeyNotFound: DefaultValue("Unknown"),
DefaultBindings: map[string]interface{}{
"Key1": "Value1"
},
}
p.Sprintf("Key1 is $Key1")
p.Sprintf("Key2 is $Key2")
func (*Printer) Fprintf ¶
Fprintf formats a map/struct according to a format specifier and writes to w. It returns the number of bytes written and any write error encountered. example:
Fprintf(w, "%Key1", map[string]interface{}{
"Key1": "Value1",
})
func (*Printer) GetKeyToken ¶
GetKeyToken returns the rune that is actually used for the key identification.