Documentation
¶
Overview ¶
Package fmt implements a simple fmt wrapper with higher performance. It will hit performance issue when `fmt.Sprintf`,`fmt.Printf` or `fmt.Fprintf` is caled too many times.Because it works based on `reflect`. The package wraps standard `fmt`, and improves performance by caching and reusing reflect result.
Index ¶
- func Errorf(format string, a ...interface{}) error
- func Fprint(w io.Writer, a ...interface{}) (n int, err error)
- func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)
- func Fprintln(w io.Writer, a ...interface{}) (n int, err error)
- func Fscan(r io.Reader, a ...interface{}) (n int, err error)
- func Fscanf(r io.Reader, format string, a ...interface{}) (n int, err error)
- func Fscanln(r io.Reader, a ...interface{}) (n int, err error)
- func Print(a ...interface{}) (n int, err error)
- func Printf(format string, a ...interface{}) (n int, err error)
- func Println(a ...interface{}) (n int, err error)
- func RegisterPrintFunc(ctx context.Context, v FormatVerb, t reflect.Type, f PrintFunc)
- func Scan(a ...interface{}) (n int, err error)
- func Scanf(format string, a ...interface{}) (n int, err error)
- func Scanln(a ...interface{}) (n int, err error)
- func Sprint(a ...interface{}) string
- func Sprintf(format string, a ...interface{}) string
- func Sprintln(a ...interface{}) string
- func Sscan(str string, a ...interface{}) (n int, err error)
- func Sscanf(str string, format string, a ...interface{}) (n int, err error)
- func Sscanln(str string, a ...interface{}) (n int, err error)
- type FormatFlags
- type FormatVerb
- type PrintFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Errorf ¶
Errorf formats according to a format specifier and returns the string as a value that satisfies error.
If the format specifier includes a %w verb with an error operand, the returned error will implement an Unwrap method returning the operand. It is invalid to include more than one %w verb or to supply it with an operand that does not implement the error interface. The %w verb is otherwise a synonym for %v.
func RegisterPrintFunc ¶
RegisterPrintFunc Register custom print function for verb and type
Types ¶
type FormatFlags ¶
type FormatFlags struct {
//Width width. set -1 if it is unset.
Width int
//Precision Precision. set -1 if it is unset.
Precision int
//Plus always print a sign for numeric values; guarantee ASCII-only output for %q (%+q)
Plus bool
//Minus pad with spaces on the right rather than the left (left-justify the field)
Minus bool
//Sharp alternate format: add leading 0b for binary (%#b), 0 for octal (%#o),
// 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p);
// for %q, print a raw (backquoted) string if strconv.CanBackquote
// returns true;
// always print a decimal point for %e, %E, %f, %F, %g and %G;
// do not remove trailing zeros for %g and %G;
// write e.g. U+0078 'x' if the character is printable for %U (%#U).
Sharp bool
//Space (space) leave a space for elided sign in numbers (% d);
//put spaces between bytes printing strings or slices in hex (% x, % X)
Space bool
//Zero pad with leading zeros rather than spaces;
//for numbers, this moves the padding after the sign
Zero bool
}
FormatFlags https://golang.org/pkg/fmt/#hdr-Printing
type FormatVerb ¶
type FormatVerb int
FormatVerb format verb for printing argument
const ( //FormatVerb_v %v FormatVerb_v FormatVerb = iota //FormatVerb_T %T FormatVerb_T //FormatVerb_t %t FormatVerb_t //FormatVerb_b %b FormatVerb_b //FormatVerb_c %c FormatVerb_c //FormatVerb_d %d FormatVerb_d //FormatVerb_o %o FormatVerb_o //FormatVerb_O %O FormatVerb_O //FormatVerb_q %q FormatVerb_q //FormatVerb_x %x FormatVerb_x //FormatVerb_X %X FormatVerb_X //FormatVerb_U %U FormatVerb_U //FormatVerb_e %e FormatVerb_e //FormatVerb_E %E FormatVerb_E //FormatVerb_f %f FormatVerb_f //FormatVerb_F %F FormatVerb_F //FormatVerb_g %g FormatVerb_g //FormatVerb_G %G FormatVerb_G //FormatVerb_p %p FormatVerb_p )
func (FormatVerb) String ¶
func (f FormatVerb) String() string
type PrintFunc ¶
type PrintFunc func(source string, verb FormatVerb, flags FormatFlags, arg interface{}) string
PrintFunc print function to print argument with type cast instead of reflect