|
|
|
|
|
by zenocon
4045 days ago
|
|
This is cool, but I find this snippet a tad bizarre: client, server := net.Pipe()
var buf bytes.Buffer
client = &recordingConn {
Conn: client,
Writer: io.MultiWriter(client, &buf),
}
While it seemingly works, it seems confusing to assign client to an internal field of a new struct, and then overwriting that same client variable with the newly created struct...not to mention passing it into MultiWriter.Anyway, I like those short posts like this. I've done similar things with embedding and struct "reconstruction" in order to elicit more testable code. It's powerful and useful, indeed. |
|
Compare:
vs The latter is less confusing to me.