ledisdb/server/util.go

24 lines
328 B
Go
Raw Normal View History

2014-06-09 13:23:32 +04:00
package server
import (
"bufio"
"errors"
)
var (
2014-10-23 09:34:27 +04:00
errLineFormat = errors.New("bad response line format")
2014-06-09 13:23:32 +04:00
)
2014-07-11 06:43:39 +04:00
func ReadLine(rb *bufio.Reader) ([]byte, error) {
2014-06-09 13:23:32 +04:00
p, err := rb.ReadSlice('\n')
if err != nil {
return nil, err
}
i := len(p) - 2
if i < 0 || p[i] != '\r' {
return nil, errLineFormat
}
return p[:i], nil
}