Hi,
Taking a look at io.ReadCloser, it's a union of the Reader and Closer
interfaces.
bytes.NewBufferString returns a bytes.Buffer* something that
implements Reader, so if we start with that class, we're half way
there.
You can add functionality to this class very easily.
type ClosingBuffer struct {
*bytes.Buffer
}
func (cb *ClosingBuffer) Close() (err os.Error) {
//we don't actually have to do anything here, since the buffer is
just some data in memory
//and the error is initialized to no-error
return
}
And use it like the following:
func main () {
cb := &ClosingBuffer{bytes.NewBufferString("Hi!")}
var rc io.ReadCloser
rc = cb
rc.Close()
}
- John