1.5 KiB
Overall code structure
This directory imports the "printf" logic as-is from the Go standard library and instruments it for redaction of sensitive data.
Overall, the original Go code is structured as follows:
-
the top-level API functions (
PrintfFprintfetc) instantiate a "printer" struct calledpp, then call thedoPrint*()methods on it. -
the
ppcontains a byte slice (pp.buf, typebuffer) that accumulates the result of formatting regardless of the final output of the API - i.e. a buffer is used even when usingFprintto anio.Writer. Only after thedoPrint()method finishes, is thebuffercopied to the finalio.Writerin theFprint*variants. -
each of the
doPrintmethods does some analysis on the argument list - quite simple for e.g.doPrintln, more intricate fordoPrintf. As part of the analysis it emits "spacing" or no-op bytes directly on thepp.buf. For exampledoPrintemits spaces between arguments directly,doPrintfemits the non-formatting characters from the format string, as well as certain constant error strings (e.g.%(BADPREC)).
Refreshing the sources
The files in this directory have been imported from
$GOROOT/src/fmt/{format,print}.go
and
$GOROOT/src/internal/fmtsort
And patched using the included .diff files.
To upgrade to a newer Go implementation, import the files anew and re-apply the patches.
See the script refresh.sh for details.