I have a socket client that read response like this:
message, err := bufio.NewReader(conn).ReadString('\n')
It works perfectly, but the ReadString method seems to have no limit on the buffer size.
Is it possible to add one? I didn't find much in bufio's document.
For example,
message, err := bufio.NewReaderSize(conn, 1024).ReadString('\n')
To limit the data read, use an io.LimitedReader. For example,
rdr := bufio.NewReader(&io.LimitedReader{R: conn, N: 1024})
message, err := rdr.ReadString('\n')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With