std/fmt
import "github.com/eugenioenko/goalchemy/std/fmt"Package fmt formats values into strings and errors with Go’s verbs, flags, widths, precisions and argument indexes. Without reflection, operands are formatted when they are nil, a boolean, integer, float or string of a predeclared type, a []byte, or a value whose type implements Formatter, GoStringer (for %#v), error or Stringer. Other operands, such as structs, maps and named basic types without methods, print as %!v(unsupported); the compiler rejects them when their static type is known. %T and the type names in bad-verb and extra-argument notes are known only for the supported basic types and print as ? otherwise. %p is unsupported. A nil pointer whose Error or String method panics prints as <nil> when the panic is a nil dereference.
Append
Section titled “Append”func Append(b []byte, a ...any) []byteAppend formats using the default formats for its operands, appends the result to the byte slice, and returns the updated slice.
Appendf
Section titled “Appendf”func Appendf(b []byte, format string, a ...any) []byteAppendf formats according to a format specifier, appends the result to the byte slice, and returns the updated slice.
Appendln
Section titled “Appendln”func Appendln(b []byte, a ...any) []byteAppendln formats using the default formats for its operands, appends the result to the byte slice, and returns the updated slice.
Errorf
Section titled “Errorf”func Errorf(format string, a ...any) errorErrorf 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. If there is more than one %w verb, the returned error will implement an Unwrap method returning a []error containing all the %w operands in the order they appear in the arguments. It is invalid to supply the %w verb with an operand that does not implement the error interface. The %w verb is otherwise a synonym for %v.
FormatString
Section titled “FormatString”func FormatString(state State, verb rune) stringFormatString returns a string representing the fully qualified formatting directive captured by the State, followed by the argument verb.
Sprint
Section titled “Sprint”func Sprint(a ...any) stringSprint formats using the default formats for its operands and returns the resulting string. Spaces are added between operands when neither is a string.
Sprintf
Section titled “Sprintf”func Sprintf(format string, a ...any) stringSprintf formats according to a format specifier and returns the resulting string.
Sprintln
Section titled “Sprintln”func Sprintln(a ...any) stringSprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended.
type Formatter
Section titled “type Formatter”type Formatter interface { Format(f State, verb rune)}Formatter is implemented by any value that has a Format method. The implementation controls how State and rune are interpreted.
type GoStringer
Section titled “type GoStringer”type GoStringer interface { GoString() string}GoStringer is implemented by any value that has a GoString method, which defines the Go syntax for that value used by %#v.
type State
Section titled “type State”type State interface { // Write is the function to call to emit formatted output to be printed. Write(b []byte) (n int, err error) // Width returns the value of the width option and whether it has been set. Width() (wid int, ok bool) // Precision returns the value of the precision option and whether it has been set. Precision() (prec int, ok bool) // Flag reports whether the flag c, a character, has been set. Flag(c int) bool}State represents the printer state passed to custom formatters. It provides access to the output buffer and the format options.
type Stringer
Section titled “type Stringer”type Stringer interface { String() string}Stringer is implemented by any value that has a String method, which defines the native format for that value.