Standard library / net/textproto
textproto.NewConn()
Combine Reader, Writer and Pipeline over an io.ReadWriteCloser. Closing the wrapper closes the underlying stream. Expected stdout: '250 ready\n'.
Formal Syntax & Structure
go syntaxgo
func NewConn(conn io.ReadWriteCloser) *ConnParameters & Attributes
| Name | Type | Description |
|---|---|---|
| conn | io.ReadWriteCloser | Underlying read/write/close stream transferred to the wrapper. |
Return Value
*Conn
Connection wrapper around provided stream.
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) }}