fmt

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: MIT Imports: 5 Imported by: 0

README

fmt

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 resuing reflect result.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Errorf

func Errorf(format string, a ...interface{}) error

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 Fprint

func Fprint(w io.Writer, a ...interface{}) (n int, err error)

func Fprintf

func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)

func Fprintln

func Fprintln(w io.Writer, a ...interface{}) (n int, err error)

func Fscan

func Fscan(r io.Reader, a ...interface{}) (n int, err error)

func Fscanf

func Fscanf(r io.Reader, format string, a ...interface{}) (n int, err error)

func Fscanln

func Fscanln(r io.Reader, a ...interface{}) (n int, err error)

func Print

func Print(a ...interface{}) (n int, err error)

func Printf

func Printf(format string, a ...interface{}) (n int, err error)

func Println

func Println(a ...interface{}) (n int, err error)

func RegisterPrintFunc

func RegisterPrintFunc(ctx context.Context, v FormatVerb, t reflect.Type, f PrintFunc)

RegisterPrintFunc Register custom print function for verb and type

func Scan

func Scan(a ...interface{}) (n int, err error)

func Scanf

func Scanf(format string, a ...interface{}) (n int, err error)

func Scanln

func Scanln(a ...interface{}) (n int, err error)

func Sprint

func Sprint(a ...interface{}) string

func Sprintf

func Sprintf(format string, a ...interface{}) string

func Sprintln

func Sprintln(a ...interface{}) string

func Sscan

func Sscan(str string, a ...interface{}) (n int, err error)

func Sscanf

func Sscanf(str string, format string, a ...interface{}) (n int, err error)

func Sscanln

func Sscanln(str string, a ...interface{}) (n int, err error)

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

Jump to

Keyboard shortcuts

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