32 lines
467 B
Go
32 lines
467 B
Go
package logger
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"regexp"
|
|
)
|
|
|
|
var regexpMultiWhitespace = regexp.MustCompile(`[\s\p{Zs}]{2,}`)
|
|
|
|
func peek(r io.Reader, n int64) (io.Reader, string, bool, error) {
|
|
if n < 0 {
|
|
n = 0
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
_, err := io.CopyN(&buf, r, n+1)
|
|
|
|
if err == io.EOF {
|
|
return &buf, buf.String(), false, nil
|
|
}
|
|
|
|
if err != nil {
|
|
return nil, "", false, err
|
|
}
|
|
|
|
s := buf.String()
|
|
s = s[:len(s)-1]
|
|
|
|
return io.MultiReader(&buf, r), s, true, nil
|
|
}
|