-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherror.go
More file actions
39 lines (32 loc) · 881 Bytes
/
error.go
File metadata and controls
39 lines (32 loc) · 881 Bytes
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
package resp
import (
"bytes"
)
// An Error is a RESP error byte slice.
type Error []byte
// NewError returns a RESP error with the given error message.
func NewError(msg string) Error {
var buf bytes.Buffer
buf.WriteByte(errorPrefix)
buf.WriteString(msg)
buf.Write(lineSuffix)
return Error(buf.Bytes())
}
// Raw returns the underlying bytes of this RESP object.
func (e Error) Raw() []byte { return e }
// Slice returns a slice pointing to this Error's message bytes.
func (e Error) Slice() []byte {
return e[1 : len(e)-2]
}
// Bytes is the same as Slice except that it returns a copied slice.
func (e Error) Bytes() []byte {
slice := e.Slice()
bytes := make([]byte, len(slice))
copy(bytes, slice)
return bytes
}
// Error returns the error message. This allows Error to satisfy the error
// interface.
func (e Error) Error() string {
return string(e.Slice())
}