Standard library / net/textproto

textproto.Reader.ReadResponse()

Read a possibly multiline response, joining message lines with newline. A mismatched expected code returns a numeric Error. Expected stdout: '250 "first\\nsecond"\n'.

Formal Syntax & Structure

go syntaxgo
func (r *Reader) ReadResponse(expectCode int) (code int, message string, err error)

Parameters & Attributes

NameTypeDescription
expectCodeintExpected numeric status prefix; nonpositive disables the code check.

Return Value

(code int, message string, err error)

Numeric code, multiline message and error.

Working Example

Example Snippetgo
package main
import (  "bufio"  "fmt"  "net/textproto"  "strings")
func main() {  r := textproto.NewReader(bufio.NewReader(strings.NewReader("250-first\r\n250 second\r\n")))  code, msg, e := r.ReadResponse(250)  check(e)  fmt.Printf("%d %q\n", code, msg)}
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)  }}
Go Reference