package main import ( "bytes" "sync" ) // SyncBuffer is a buffer that the test and the client use at once. type SyncBuffer struct { mutex sync.Mutex buffer bytes.Buffer } func (b *SyncBuffer) Write(p []byte) (int, error) { b.mutex.Lock() defer b.mutex.Unlock() return b.buffer.Write(p) } func (b *SyncBuffer) String() string { b.mutex.Lock() defer b.mutex.Unlock() return b.buffer.String() }