Skip to content

Commit 0e5a3c7

Browse files
committed
Make CallbackWriter private
1 parent ad383ef commit 0e5a3c7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

‎io.go‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,27 @@ package f
22

33
import (
44
"bytes"
5+
"io"
56
)
67

78
const defaultBufferSize = 1024
89

9-
// CallbackWriter is a custom writer that processes each line calling the callback.
10-
type CallbackWriter struct {
10+
// callbackWriter is a custom writer that processes each line calling the callback.
11+
type callbackWriter struct {
1112
callback func(line string)
1213
buffer []byte
1314
}
1415

1516
// NewCallbackWriter creates a new CallbackWriter.
16-
func NewCallbackWriter(process func(line string)) *CallbackWriter {
17-
return &CallbackWriter{
17+
func NewCallbackWriter(process func(line string)) io.WriteCloser {
18+
return &callbackWriter{
1819
callback: process,
1920
buffer: make([]byte, 0, defaultBufferSize),
2021
}
2122
}
2223

2324
// Write implements the io.Writer interface.
24-
func (p *CallbackWriter) Write(data []byte) (int, error) {
25+
func (p *callbackWriter) Write(data []byte) (int, error) {
2526
p.buffer = append(p.buffer, data...)
2627
for {
2728
idx := bytes.IndexByte(p.buffer, '\n')
@@ -35,7 +36,7 @@ func (p *CallbackWriter) Write(data []byte) (int, error) {
3536
return len(data), nil
3637
}
3738

38-
func (p *CallbackWriter) Close() error {
39+
func (p *callbackWriter) Close() error {
3940
if len(p.buffer) > 0 {
4041
p.callback(string(p.buffer))
4142
p.buffer = p.buffer[:0]

0 commit comments

Comments
 (0)