fmt.Fprintf
The fmt functions that write formatted text to a destination you choose, such as os.Stderr, a file or an HTTP response.
In more detail
The destination is any io.Writer, so the same call can print to a terminal, a file or a web response. Command-line tools use fmt.Fprintln(os.Stderr, ...) for usage and error messages so standard output stays clean for results.
Example
fmt.Fprintf(os.Stderr, "%d unhealthy\n", unhealthy)Related terms
- io.Writer — The Go interface for anything you can write bytes to, such as a file, standard output, a buffer or an HTTP response.
- standard output and standard error — The two channels a program writes normal output (stdout) and error messages (stderr) to, plus stdin for input.
- fmt.Printf — The fmt function that prints text built from a format string, in which verbs such as %s and %d are replaced by the arguments.
Taught in
- Your First Program and go run — Concurrent Systems Programming with Go
- Files and the os Package — Concurrent Systems Programming with Go
- Parsing Arguments with flag — Concurrent Systems Programming with Go
- Serving HTTP with net/http Server — Concurrent Systems Programming with Go