# README
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 (
Printf
Fprintf
etc) instantiate a "printer" struct calledpp
, then call thedoPrint*()
methods on it. -
the
pp
contains 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 usingFprint
to anio.Writer
. Only after thedoPrint()
method finishes, is thebuffer
copied to the finalio.Writer
in theFprint*
variants. -
each of the
doPrint
methods 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 exampledoPrint
emits spaces between arguments directly,doPrintf
emits 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.