Standard library / net/textproto
textproto.Reader.ReadCodeLine()
Parse a single numeric status line; expectCode matches a decimal prefix, and a nonpositive value disables the status check. Expected stdout: '250 ready\n'.
Formal Syntax & Structure
go syntaxgo
func (r *Reader) ReadCodeLine(expectCode int) (code int, message string, err error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| expectCode | int | Expected numeric status prefix; nonpositive disables the code check. |
Return Value
(code int, message string, err error)
Numeric code, 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 ready\r\n"))) code, msg, e := r.ReadCodeLine(25) check(e) fmt.Println(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) }}