Make network as a separae interface

This commit is contained in:
9seconds
2021-03-11 04:57:07 +03:00
parent 299c6478c2
commit 24add0dce4
8 changed files with 90 additions and 63 deletions
+13 -2
View File
@@ -4,13 +4,14 @@ import (
"context"
"errors"
"net"
"net/http"
"time"
)
const (
DefaultTimeout = 10 * time.Second
DefaultDNSTimeout = time.Second
DefaultHTTPTimeout = DefaultTimeout
DefaultIdleTimeout = time.Minute
DefaultHTTPTimeout = 5 * time.Second
DefaultBufferSize = 4096
ProxyDialerOpenThreshold = 5
@@ -18,6 +19,8 @@ const (
ProxyDialerResetFailuresTimeout = 10 * time.Second
DefaultDOHHostname = "9.9.9.9"
DNSTimeout = 5 * time.Second
)
var (
@@ -29,3 +32,11 @@ type Dialer interface {
Dial(network, address string) (net.Conn, error)
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}
type Network interface {
Dialer
DNSResolve(network, hostname string) (ips []string, err error)
MakeHTTPClient(timeout time.Duration) *http.Client
IdleTimeout() time.Duration
}