network

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NetDialer Dialer = &net.Dialer{
		Timeout: connectTimeout,
	}

	DNSResolver Resolver = &net.Resolver{
		Dial: NetDialer.DialContext,
	}

	CookieJar = func() *cookiejar.Jar {
		jar, err := cookiejar.New(nil)
		if err != nil {
			panic(err)
		}

		return jar
	}()

	HTTPClient = &http.Client{
		Jar: CookieJar,
		Transport: &http.Transport{
			Proxy:       http.ProxyFromEnvironment,
			DialContext: NetDialer.DialContext,
		},
		Timeout: httpTimeout,
	}

	HTTPClientV4 = &http.Client{
		Jar: CookieJar,
		Transport: &http.Transport{
			Proxy: http.ProxyFromEnvironment,
			DialContext: func(ctx context.Context, _, address string) (net.Conn, error) {
				return NetDialer.DialContext(ctx, "tcp4", address)
			},
		},
		Timeout: httpTimeout,
	}

	HTTPClientV6 = &http.Client{
		Jar: CookieJar,
		Transport: &http.Transport{
			Proxy: http.ProxyFromEnvironment,
			DialContext: func(ctx context.Context, _, address string) (net.Conn, error) {
				return NetDialer.DialContext(ctx, "tcp6", address)
			},
		},
		Timeout: httpTimeout,
	}
)

Functions

func CloseResponse

func CloseResponse(resp *http.Response) error

func DoJSONRequest

func DoJSONRequest(ctx context.Context, url string, target interface{}) error

func DoJSONRequestWithClient

func DoJSONRequestWithClient(
	ctx context.Context,
	client *http.Client,
	url string,
	target interface{},
) error

func NewRequest

func NewRequest(ctx context.Context, url string) *http.Request

func SendRequest

func SendRequest(client *http.Client, req *http.Request) (*http.Response, error)

Types

type Dialer

type Dialer interface {
	DialContext(context.Context, string, string) (net.Conn, error)
}

type Resolver

type Resolver interface {
	LookupHost(context.Context, string) ([]string, error)
	LookupAddr(context.Context, string) ([]string, error)
	LookupMX(context.Context, string) ([]*net.MX, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL