Standard library / fmt
fmt.State
Writer and formatting options passed to Formatter. Width and Precision return value plus presence; Flag reports whether a flag is set. Expected stdout: '5 true true\n'.
Formal Syntax & Structure
go syntaxgo
type State interface { Write(b []byte) (n int, err error); Width() (wid int, ok bool); Precision() (prec int, ok bool); Flag(c int) bool }Working Example
Example Snippetgo
package main
import ( "fmt")
type probe int
func (p probe) Format(s fmt.State, v rune) { w, ok := s.Width() fmt.Fprintf(s, "%d %v %v", w, ok, s.Flag('0'))}func main() { fmt.Printf("%05v\n", probe(0))}