-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
92 lines (86 loc) · 2.42 KB
/
errors.go
File metadata and controls
92 lines (86 loc) · 2.42 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package gonnect
import (
"fmt"
"net"
"os"
"syscall"
)
// NoSuchHost returns a net.Error representing a DNS lookup failure for the specified host.
// The host parameter is the hostname that was looked up (e.g. example.com).
// The srv parameter is the DNS server address (e.g. 8.8.8.8:53).
func NoSuchHost(host, srv string) *net.DNSError {
return &net.DNSError{
Err: "no such host",
Name: host, // e.g. example.com
Server: srv, // e.g. 8.8.8.8:53
IsTimeout: false,
IsTemporary: true,
IsNotFound: true,
}
}
// DnsReqErr returns a net.DNSError representing a DNS request failure.
// The host parameter is the hostname that was looked up (e.g. example.com).
// The srv parameter is the DNS server address (e.g. 8.8.8.8:53).
func DnsReqErr(host, srv string) error {
return &net.DNSError{
Err: fmt.Sprintf(
"dial udp %s: connect: connection refused",
srv,
),
Name: host, // e.g. example.com
Server: srv, // e.g. 8.8.8.8:53
IsTimeout: false,
IsTemporary: true,
IsNotFound: false,
}
}
// ConnClosed returns a net.Error representing an operation on a closed network connection.
// The op parameter is the operation being performed (e.g. "read", "write").
// The network parameter is the network type (e.g. "tcp", "udp").
// src and addr represent the source and destination addresses of the connection.
func ConnClosed(op, network string, src, addr net.Addr) net.Error {
return &net.OpError{
Op: op,
Source: src,
Addr: addr,
Net: network,
Err: net.ErrClosed,
}
}
// ConnRefused returns an error representing a connection refusal.
// The n parameter is the network type (e.g. "tcp", "udp").
// The a parameter is the address that refused the connection.
func ConnRefused(n, a string) error {
return &net.OpError{
Op: "dial",
Net: n,
Source: nil,
Addr: &NetAddr{
Net: n,
Addr: a,
},
Err: &os.SyscallError{
Syscall: "connect",
Err: syscall.ECONNREFUSED,
},
}
}
// ListenDeniedErr returns an error representing a permission denied when
// attempting to listen on an address.
// The n parameter is the network type (e.g. "tcp", "udp").
// The a parameter is the address that denied the listen attempt.
func ListenDeniedErr(n, a string) error {
return &net.OpError{
Op: "listen",
Net: n,
Source: nil,
Addr: &NetAddr{
Net: n,
Addr: a,
},
Err: &os.SyscallError{
Syscall: "bind",
Err: syscall.EACCES,
},
}
}