STRING::ERRORF 1g 2024-03-01 laplante@plcb.ca GOWEB/STRING — Formatted Error Outputtitle: “string::errorf”
Version:“1.0.0”
Date: “2024-03-01 ”
Author: “laplante@plcb.ca”
section: “1g”
string::errorf Formatted Error Output
string::errorf(format [, args])
errorf(format [, args])
The errorf function is equivalent to Go’s printf, with the output directed as follows:
stderr.Formatting follows Go’s fmt.Printf conventions and supports the following verbs:
%!v(MISSING) — Value in default format. When printing structs, %!v(MISSING) adds field names.%!v(MISSING) — Go-syntax representation of the value.%!T(MISSING) — Go-syntax representation of the value’s type.% — Literal percent sign (no operand).%!t(MISSING) — The word true or false.%!b(MISSING) — Base 2.%!c(MISSING) — Character represented by the corresponding Unicode code point.%!d(MISSING) — Base 10.%!o(MISSING) — Base 8.%!O(MISSING) — Base 8 with 0o prefix.%!q(MISSING) — Single-quoted character literal safely escaped with Go syntax.%!x(MISSING) — Base 16, lower-case.%!X(MISSING) — Base 16, upper-case.%!U(MISSING) — Unicode format: U+1234.%!b(MISSING) — Scientific notation with exponent as power of two (strconv.FormatFloat with 'b').%!e(MISSING) / %!E(MISSING) — Scientific notation (e or E).%!f(MISSING) / %!F(MISSING) — Decimal point, no exponent.%!g(MISSING) / %!G(MISSING) — Compact form (%!e(MISSING)/%!E(MISSING) for large exponents, otherwise %!f(MISSING)/%!F(MISSING)).%!x(MISSING) / %!X(MISSING) — Hexadecimal notation with decimal power of two exponent.%!s(MISSING) — Uninterpreted bytes of the string.%!q(MISSING) — Double-quoted string safely escaped with Go syntax.%!x(MISSING) / %!X(MISSING) — Base 16, lower-/upper-case, two characters per byte.%!p(MISSING) — Base 16 with 0x prefix.%!b(MISSING), %!d(MISSING), %!o(MISSING), %!x(MISSING), %!X(MISSING) also apply to pointers.%!v(MISSING)bool: %!t(MISSING)int, int8, etc.: %!d(MISSING) (%!x(MISSING) with %!v(MISSING))uint, uint8, etc.: %!d(MISSING) (%!x(MISSING) with %!v(MISSING))float32, float64: %!g(MISSING)string: %!s(MISSING)Width is specified by a decimal number before the verb.
Precision follows a period (.). Examples:
%!f(MISSING) — Default width and precision.%!f(MISSING) — Width 9, default precision.%!f(MISSING) — Default width, precision 2.%!f(MISSING) — Width 9, precision 2.%!f(MISSING) — Width 9, precision 0.Width and precision can be replaced by * to read the value from the next operand (type int).
%!x(MISSING)/%!X(MISSING) string formats, precision is in bytes.%!g(MISSING)/%!G(MISSING)).%!q(MISSING) with runes: invalid Unicode is replaced by U+FFFD.+ — Always show sign for numbers; force ASCII for %!q(MISSING) (%!q(MISSING)).- — Left-justify within the field.# — Alternate form (e.g., 0b, 0o, 0x prefixes; raw strings for %!q(MISSING); keep trailing zeros for %!g(MISSING)/%!G(MISSING)).%!x(MISSING)/%!X(MISSING).0 — Zero-pad numbers; ignored for strings.res={{
a := [1, 2.2, "3"];
errorf("%!T(MISSING) %!T(MISSING) %!T(MISSING)\n", a);
}};
Returns:
res = int64 float64 string
res={{
a := [1, 2.2, "3", [1, 2, 3]];
errorf("%!T(MISSING) %!T(MISSING) %!T(MISSING) %!T(MISSING)\n", a);
}};
Returns:
res = int64 float64 string int64
%!!(MISSING)(EXTRA int64=2, int64=3)