-
Notifications
You must be signed in to change notification settings - Fork 183
/
bytes_buf.go
46 lines (38 loc) · 918 Bytes
/
bytes_buf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package strutil
import (
"bytes"
"fmt"
"strings"
)
// Buffer wrap and extends the bytes.Buffer
type Buffer struct {
bytes.Buffer
}
// NewEmptyBuffer instance
func NewEmptyBuffer() *Buffer {
return &Buffer{}
}
// QuietWriteByte to buffer
func (b *Buffer) QuietWriteByte(c byte) {
_ = b.WriteByte(c)
}
// QuietWritef write message to buffer
func (b *Buffer) QuietWritef(tpl string, vs ...interface{}) {
_, _ = b.WriteString(fmt.Sprintf(tpl, vs...))
}
// QuietWriteln write message to buffer with newline
func (b *Buffer) QuietWriteln(ss ...string) {
_, _ = b.WriteString(strings.Join(ss, ""))
_ = b.WriteByte('\n')
}
// QuietWriteString to buffer
func (b *Buffer) QuietWriteString(ss ...string) {
_, _ = b.WriteString(strings.Join(ss, ""))
}
// MustWriteString to buffer
func (b *Buffer) MustWriteString(ss ...string) {
_, err := b.WriteString(strings.Join(ss, ""))
if err != nil {
panic(err)
}
}