In Go, a TCP connection (net.Conn) is a io.ReadWriteCloser. I\'d like to test my network code by simulating a TCP connection. There are two requirements that I have:
Why not using bytes.Buffer? It's an io.ReadWriter and has a String method to get the stored data. If you need to make it an io.ReadWriteCloser, you could define you own type:
type CloseableBuffer struct {
bytes.Buffer
}
and define a Close method:
func (b *CloseableBuffer) Close() error {
return nil
}