Golang net/textproto.Reader.ReadResponse() function example
package net/textproto
Golang net/textproto.Reader.ReadResponse() function usage example
package main
import (
"bufio"
"bytes"
"fmt"
"net/textproto"
)
func main() {
readbuffer := bytes.NewBuffer([]byte("200 Command okay.\n"))
reader := *bufio.NewReader(readbuffer)
tpReader := textproto.NewReader(bufio.NewReader(&reader))
//fmt.Println(&tpReader)
code, msg, err := tpReader.ReadResponse(200) // read code 200
if err != nil {
fmt.Println("Read error :", err) // ReadResponse returns with err set to &Error{code, message}
return
}
fmt.Println("Code :", code)
fmt.Println("Message :", msg)
}
Output :
Code : 200
Message : Command okay.
Reference :
Advertisement
Something interesting
Tutorials
+19.1k Golang : Display list of time zones with GMT
+9.8k Golang : Get current, epoch time and display by year, month and day
+7.8k Golang : Regular Expression find string example
+35.5k Golang : Smarter Error Handling with strings.Contains()
+12.7k Golang : zlib compress file example
+24.5k Golang : Time slice or date sort and reverse sort example
+5.7k Fix yum-complete-transaction error
+14.2k Golang : Convert IP version 6 address to integer or decimal number
+55.3k Golang : Unmarshal JSON from http response
+4.7k Unix/Linux : How to pipe/save output of a command to file?
+6k Fontello : How to load and use fonts?