srvcache

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2019 License: Apache-2.0 Imports: 9 Imported by: 5 modules, 6 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package srvcache provides a caching SRV lookup service that creates a short term cache of SRV answers - it does not comply with DNS protocols like the timings set by DNS servers, its more a short term - think 5 seconds - buffer to avoid hitting the dns servers repeatedly

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicServer

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

BasicServer is a representation of a network server host and port, implements Server

func (*BasicServer) Host

func (s *BasicServer) Host() string

Host retrieves the host for the server

func (*BasicServer) HostPort

func (s *BasicServer) HostPort() string

HostPort is a string in hostname:port format

func (*BasicServer) Port

func (s *BasicServer) Port() uint16

Port retrieves the port for the server

func (*BasicServer) Scheme

func (s *BasicServer) Scheme() string

Scheme retrieves the url scheme

func (*BasicServer) SetHost

func (s *BasicServer) SetHost(host string)

SetHost sets the host for the server

func (*BasicServer) SetPort

func (s *BasicServer) SetPort(port int)

SetPort sets the port for the server

func (*BasicServer) SetScheme

func (s *BasicServer) SetScheme(scheme string)

SetScheme sets the url scheme

func (*BasicServer) String

func (s *BasicServer) String() string

String is a string representation of the server in url format

func (*BasicServer) URL

func (s *BasicServer) URL() (u *url.URL, err error)

URL creates a correct url from the server if scheme is known

type Cache

type Cache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Cache provides a fixed term DNS cache for SRV lookups

func New

func New(identity string, maxAge time.Duration, resolver Resolver, log *logrus.Entry) *Cache

New creates a new Cache

func (*Cache) LookupSRV

func (c *Cache) LookupSRV(service string, proto string, name string) (cname string, addrs []*net.SRV, err error)

LookupSRV has the same signature as net.LookupSRV but performs caching

func (*Cache) LookupSrvServers

func (c *Cache) LookupSrvServers(service string, proto string, name string, scheme string) (s Servers, err error)

LookupSrvServers performs a cached SRV lookup and returns a Servers collection

type Resolver

type Resolver func(service string, proto string, name string) (cname string, addrs []*net.SRV, err error)

Resolver performs dns lookup like net.LookupSRV

type Server

type Server interface {
	Host() string
	SetHost(string)
	Port() uint16
	SetPort(int)
	Scheme() string
	SetScheme(string)
	String() string
	URL() (u *url.URL, err error)
	HostPort() string
}

Server is a Server that can be stored in the collection

func NewServer

func NewServer(host string, port int, scheme string) Server

NewServer creates a new server instance

type Servers

type Servers interface {
	Count() int
	Strings() (urls []string)
	URLs() (urls []*url.URL, err error)
	HostPorts() (hps []string)
	Servers() []Server
	Each(func(Server))
}

Servers is a collection of server urls

func NewServers

func NewServers(s ...Server) Servers

NewServers creates a new server collection

func StringHostsToServers

func StringHostsToServers(hosts []string, scheme string) (servers Servers, err error)

StringHostsToServers converts an array of servers like host:123 into an array of Servers collection

if an empty scheme is given the string will be parsed by a url parser and the embedded scheme will be used, if that does not parse into a valid url then an error will be returned

Jump to

Keyboard shortcuts

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