srv

package module
v0.0.0-...-11691b8 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2019 License: BSD-2-Clause Imports: 6 Imported by: 0

README

srv

GoDoc

go.spiff.io/srv is a simple package for looking up and dialing hosts described in SRV records. It doesn't do much else, but does include a srvproxy command that provides a very basic TCP proxy for services described in SRV records.

Support for UDP in srvproxy is not yet available.

Install

$ go get go.spiff.io/srv

To install srvproxy:

$ go get go.spiff.io/srv/cmd/srvproxy

License

This package and subpackages are licensed under a BSD 2-Clause license.

Documentation

Overview

Package srv is a simple package for looking up and dialing hosts described in SRV records.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAddrs = errors.New("no addresses found")

ErrNoAddrs is returned if no names were returned in a request for SRV records.

Functions

func Dial

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

Dial is a convenience function for DialContext(context.Background, network, address). See DialContext for more information.

func DialContext

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

DialContext looks up SRV records for the address and dials a randomly selected host and port from the returned records.

func DialSRV

func DialSRV(ctx context.Context, service, proto, name string) (net.Conn, error)

DialSRV looks up SRV records for the given service, proto, and name and dials a randomly selected host and port from the returned records.

Types

type Addr

type Addr struct {
	Net string
	SRV *net.SRV
}

Addr contains a network (for use in net.Dial) and a SRV record. It is not a fully-resolved address.

func LookupAddrs

func LookupAddrs(ctx context.Context, service, proto, name string, limit int) ([]*Addr, error)

LookupAddrs looks up SRV records. See (*Dialer).LookupAddrs for more information, as this calls it on a default Dialer.

func (*Addr) Network

func (a *Addr) Network() string

func (*Addr) String

func (a *Addr) String() string

type DialFunc

type DialFunc func(ctx context.Context, network, address string) (net.Conn, error)

DialFunc is any dial function compatible with (*net.Dialer).DialContext.

type Dialer

type Dialer struct {
	DialFunc   DialFunc
	Resolver   Resolver
	GetNetwork GetNetworkFunc
	RandInt    func(int) int
}

Dialer looks up services in using SRV records and dials host:port combinations described by SRV records.

func (*Dialer) Dial

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

Dial is a convenience function for DialContext(context.Background, network, address). See DialContext for more information.

func (*Dialer) DialContext

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

DialContext looks up SRV records for the address and dials a randomly selected host and port from the returned records.

Unlike DialSRV, if no SRV records are found for the given address, it will attempt to dial the address normally.

func (*Dialer) DialSRV

func (d *Dialer) DialSRV(ctx context.Context, service, proto, name string) (net.Conn, error)

DialSRV looks up SRV records for the given service, proto, and name and dials a randomly selected host and port from the returned records.

func (*Dialer) LookupAddrs

func (d *Dialer) LookupAddrs(ctx context.Context, service, proto, name string, limit int) ([]*Addr, error)

LookupAddrs looks up SRV records for the given service, proto, and name and returns up to limit addresses for them.

type GetNetworkFunc

type GetNetworkFunc func(service, proto, name string) string

GetNetworkFunc is a callback used by Dialer. Given a service and proto (including _s using standard names), the function should return a network supported by net.Dial, such as "tcp" or "udp". If the names aren't recognized, it should return an empty string.

type Resolver

type Resolver interface {
	LookupSRV(ctx context.Context, service, proto, name string) (cname string, addrs []*net.SRV, err error)
}

Resolver is anything that performs DNS lookups for SRV records. This is made to be compatible with *net.Resolver.

Directories

Path Synopsis
cmd
srvproxy
Program srvproxy is a simply TCP proxy that accepts connections and proxies them to an upstream server described by SRV records.
Program srvproxy is a simply TCP proxy that accepts connections and proxies them to an upstream server described by SRV records.

Jump to

Keyboard shortcuts

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