-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplyerror.go
More file actions
43 lines (37 loc) · 1.47 KB
/
Copy pathreplyerror.go
File metadata and controls
43 lines (37 loc) · 1.47 KB
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
42
43
package socks5
import "fmt"
type ReplyError struct {
ReplyCode
}
var replyErrorText = []string{
ReplySuccess: "success",
ReplyGeneralFailure: "general failure",
ReplyConnectionNotAllowed: "connection not allowed",
ReplyNetworkUnreachable: "network unreachable",
ReplyHostUnreachable: "host unreachable",
ReplyConnectionRefused: "connection refused",
ReplyTTLExpired: "ttl expired",
ReplyCommandNotSupported: "command not supported",
ReplyAddrTypeNotSupported: "address type not supported",
}
var (
ErrReply = ReplyError{ReplyGeneralFailure} // for testing against with errors.Is()
ErrReplySuccess = ReplyError{ReplySuccess}
ErrReplyGeneralFailure = ReplyError{ReplyGeneralFailure}
ErrReplyConnectionNotAllowed = ReplyError{ReplyConnectionNotAllowed}
ErrReplyNetworkUnreachable = ReplyError{ReplyNetworkUnreachable}
ErrReplyHostUnreachable = ReplyError{ReplyHostUnreachable}
ErrReplyConnectionRefused = ReplyError{ReplyConnectionRefused}
ErrReplyTTLExpired = ReplyError{ReplyTTLExpired}
ErrReplyCommandNotSupported = ReplyError{ReplyCommandNotSupported}
ErrReplyAddrTypeNotSupported = ReplyError{ReplyAddrTypeNotSupported}
)
func (re ReplyError) Error() string {
if int(re.ReplyCode) < len(replyErrorText) {
return replyErrorText[re.ReplyCode]
}
return fmt.Sprintf("socks5code(%v)", re.ReplyCode)
}
func (re ReplyError) Is(target error) (yes bool) {
return target == ErrReply
}