Standard library / net/textproto
textproto.Writer.PrintfLine()
Format a line, append CRLF and flush. Validate values to avoid injecting additional protocol lines. Expected stdout: '"VALUE 7\\r\\n"\n'.
Formal Syntax & Structure
go syntaxgo
func (w *Writer) PrintfLine(format string, args ...any) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| format | string | fmt-style format string; do not allow untrusted line breaks in commands. |
| args | ...any | Optional values for format placeholders. |
Return Value
error
Nil on success, otherwise the operation error.
Working Example
Example Snippetgo
package main
import ( "bufio" "bytes" "fmt" "net/textproto")
func main() { var b bytes.Buffer w := textproto.NewWriter(bufio.NewWriter(&b)) check(w.PrintfLine("VALUE %d", 7)) fmt.Printf("%q\n", b.String())}
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}