mirror of
https://github.com/hanzo-fi/go-libs.git
synced 2026-10-30 20:53:44 +00:00
Migrate all internal usages of github.com/pkg/errors to the Go standard library: errors.New/Is/As map directly to the stdlib equivalents, while errors.Wrap/Wrapf become fmt.Errorf(..., %w, err). github.com/pkg/errors is no longer a direct dependency (remains indirect via watermill). Constraint: errors.Wrap returns nil on nil input; fmt.Errorf does not, so run.go's "executing migration" wrap was rewritten as an explicit nil check Confidence: high Scope-risk: narrow
26 lines
457 B
Go
26 lines
457 B
Go
package logging
|
|
|
|
import (
|
|
"bufio"
|
|
"errors"
|
|
"io"
|
|
)
|
|
|
|
func StreamReader(logger Logger, r io.Reader, fn func(Logger, ...any)) {
|
|
br := bufio.NewReader(r)
|
|
for {
|
|
// todo: handle isPrefix for lines bigger than 65 characters
|
|
line, _, err := br.ReadLine()
|
|
if err != nil {
|
|
switch {
|
|
case errors.Is(err, io.EOF):
|
|
return
|
|
default:
|
|
logger.Errorf("error reading container logs buffer: %s", err)
|
|
}
|
|
return
|
|
}
|
|
fn(logger, string(line))
|
|
}
|
|
}
|