micro/util/buf/buf.go

28 lines
428 B
Go
Raw Permalink Normal View History

package buf
2015-01-13 23:31:27 +00:00
import (
"bytes"
"io"
2015-01-13 23:31:27 +00:00
)
var _ io.Closer = &Buffer{}
// Buffer bytes.Buffer wrapper to satisfie io.Closer interface
type Buffer struct {
*bytes.Buffer
2015-01-13 23:31:27 +00:00
}
// Close reset buffer contents
func (b *Buffer) Close() error {
b.Buffer.Reset()
2015-01-13 23:31:27 +00:00
return nil
}
// New creates new buffer that satisfies Closer interface
func New(b *bytes.Buffer) *Buffer {
if b == nil {
b = bytes.NewBuffer(nil)
}
return &Buffer{b}
}