dialsrv

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 7 Imported by: 0

README

koron-go/dialsrv

PkgGoDev Actions/Go Go Report Card

Dialer with SRV lookup.

Sample codes

HTTP
import "github.com/koron-go/dialsrv"

// query SRV records for "_myservice._tcp.example.com" then make HTTP GET.
r, err := dialsrv.HTTPClient.Get("http://srv+myservice+example.com/")
// TODO: work with r and err as usual.
// GET from example.com without SRV.
r, err := dialsrv.HTTPClient.Get("http://example.com/")
// TODO: work with r and err as usual.
import "net/http"

// replace http.DefaultClient
http.DefaultClient = dialsrv.HTTPClient
r, err := http.Get("http://srv+myservice+example.com/")
// TODO: work with r and err as usual.
Dialer
import "net"
import "github.com/koron-go/dialsrv"

// wrap *net.Dialer with SRV record querying
d := dialsrv.New(&net.Dialer{/* net.Dialer with your configurations */})

Acceptable formats

  • srv+{service}+{hostname} - SRV for _{service}._{network}.{hostname}
  • srv+{hostname} - SRV for {hostname}

Documentation

Overview

Package dialsrv provides a net.Dialer implementation that can reference SRV records to DNS servers.

Index

Constants

This section is empty.

Variables

View Source
var HTTPClient = &http.Client{
	Transport: HTTPTransport,
}

HTTPClient is replacement for http.DefaultClient

View Source
var HTTPTransport = &http.Transport{
	Proxy: http.ProxyFromEnvironment,
	DialContext: New(&net.Dialer{
		Timeout:   30 * time.Second,
		KeepAlive: 30 * time.Second,
	}).DialContext,
	ForceAttemptHTTP2:     true,
	MaxIdleConns:          100,
	IdleConnTimeout:       90 * time.Second,
	TLSHandshakeTimeout:   10 * time.Second,
	ExpectContinueTimeout: 1 * time.Second,
}

HTTPTransport is replacement for http.DefaultTransport

Functions

This section is empty.

Types

type Dialer

type Dialer struct {
	// contains filtered or unexported fields
}

Dialer wraps net.Dialer with SRV lookup.

func New

func New(d *net.Dialer) *Dialer

New creates a new Dialer with base *net.Dialer.

func (*Dialer) Dial

func (d *Dialer) Dial(network, address string) (net.Conn, error)

Dial connects to the address on the named network.

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext connects to the address on the named network using the provided context.

type FlavoredAddr

type FlavoredAddr struct {
	Network string
	Service string
	Proto   string
	Name    string
}

FlavoredAddr represents SRV flavored address.

func (*FlavoredAddr) String

func (fa *FlavoredAddr) String() string

String returns FlavoredAddr's string representation.

Jump to

Keyboard shortcuts

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