net/textproto

Guided tour · Networking · pkg.go.dev →

Implements generic text protocols in the SMTP/HTTP/NNTP style: numbered command/response, MIME headers, pipelining.

When to reach for it

You're writing a client or server for a text protocol that's not HTTP. textproto handles the fiddly parts: canonicalized header names, reading folded header lines, sending/reading responses with continuation lines.

MIMEHeader

CanonicalMIMEHeaderKey

HTTP, SMTP, news all canonicalize header names the same way. http.Header is really a textproto.MIMEHeader.

textproto.CanonicalMIMEHeaderKey("content-type")  // "Content-Type"