Standard library / net/textproto
textproto.Conn
Text-protocol connection with embedded Reader, Writer and Pipeline. Their promoted methods are documented on the owning types. Coordinate command/response order and set deadlines on the underlying stream. Expected stdout: '250 ready\n'.
Formal Syntax & Structure
go syntaxgo
type Conn struct { Reader Writer Pipeline}Working Example
Example Snippetgo
package main
import ( "fmt" "io" "net" "net/textproto" "time")
func main() { c, s := net.Pipe() defer c.Close() defer s.Close() check(c.SetDeadline(time.Now().Add(3 * time.Second))) check(s.SetDeadline(time.Now().Add(3 * time.Second))) tp := textproto.NewConn(c) defer tp.Close() done := make(chan error, 1) go func() { _, e := io.WriteString(s, "250 ready\r\n"); done <- e }() code, msg, e := tp.ReadCodeLine(250) check(e) check(<-done) 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) }}