Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Formatter ¶
Formatter allows format structs into string. Formatting rules are described with special mini language which allows to align fields.
Formatting language description. Format string is a regular string which may includes special substitution forms. Substitution forms are surrounded with curly braces. For instance: "foo {%a} bar". This is a simple format string with one trivial substitution ("{%a}") inside. Substitution has a following format: {[[-]width[%]]:name}. Where "width" is a number of chars which will be allocated for substitution's result text. Optional minus sign sets aligning to the left, instead of right which is the default. With % sign width can be set in percents instead of absolute value. Percent width values are calculated during formatter creation depends on the given parameters. "format" is a format string like in Printf is used. Format verbs should be prefixed with percent sign. Available format verb values depends on data map parameter passed to the Format method. Examples.
If data is map[string]string{
"a": "A",
"b": "B",
}
"foo {%a} bar {%b}" formatted to "foo A bar B" "{{{10:%a-%b}}}" formatted to "{ A-B}" "{{{-10:%a-%b}}}" formatted to "{A-B }"
func NewFormatter ¶
NewFormatter returns new Formatter object for the given format pattern.