/
error.go
41 lines (33 loc) · 1.07 KB
/
error.go
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
40
41
package netx
import (
"errors"
"net"
)
// Timeout returns a new network error representing a timeout.
func Timeout(msg string) net.Error { return &timeout{msg} }
type timeout struct{ msg string }
func (t *timeout) Error() string { return t.msg }
func (t *timeout) Timeout() bool { return true }
func (t *timeout) Temporary() bool { return true }
// IsTemporary checks whether err is a temporary error.
func IsTemporary(err error) bool {
e, ok := err.(interface {
Temporary() bool
})
return ok && e != nil && e.Temporary()
}
// IsTimeout checks whether err resulted from a timeout.
func IsTimeout(err error) bool {
e, ok := err.(interface {
Timeout() bool
})
return ok && e != nil && e.Timeout()
}
var (
// ErrLineTooLong should be used by line-based protocol readers that detect
// a line longer than they were configured to handle.
ErrLineTooLong = errors.New("the line is too long")
// ErrNoPipeline should be used by handlers that detect an attempt to use
// pipelining when they don't support it.
ErrNoPipeline = errors.New("pipelining is not supported")
)