Documentation
¶
Index ¶
- Variables
- func ServeDNS(h Handler) dns.Handler
- func ServeHTTP(h Handler) http.Handler
- func ShutdownAll(ctx context.Context, ss ...Shutdowner) (err error)
- type Config
- type Error
- type ForwardedHeader
- type Handler
- type HandlerFunc
- type ListenConfig
- type Listener
- type Record
- type RecordInput
- type Request
- type ResolverConfig
- type Response
- type ServerConfig
- type ShutdownFunc
- type Shutdowner
- type Zone
- type ZoneInput
Constants ¶
This section is empty.
Variables ¶
var ( ErrZoneNotFound = errors.New("zone not found") ErrRecordNotFound = errors.New("record not found") )
var (
ErrProtoUnknown = Error{/* contains filtered or unexported fields */}
)
var ( // ErrTimeout is returned when request processing did not served // within a configured duration. ErrTimeout = Error{/* contains filtered or unexported fields */} )
Functions ¶
func ShutdownAll ¶
func ShutdownAll(ctx context.Context, ss ...Shutdowner) (err error)
ShutdownAll executes all passed ShutdownFunc concurrently.
Types ¶
type Config ¶
type Config struct {
// ServerStoragePath is the location of the database file to keep
// zones and associated records.
ServerStoragePath string `hcl:"server_storage_path,optional"`
// ServerShutdownTimeout specifies a timeout for graceful shutdown
// of a server. When timeout expires, the termination will be enforced.
ServerShutdownTimeout string `hcl:"server_shutdown_timeout,optional"`
// Servers is a list of servers to process user requests.
Servers []ServerConfig `hcl:"server,block"`
}
Config is a structure that holds configurations for the whole DNS server.
func DecodeConfig ¶
DecodeConfig opens the given filename and loads the configuration.
Method returns an error, when file does not exist, configuration syntax is incorrect or the decoding failed.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error represents a server error.
type ForwardedHeader ¶
func ParseForwarded ¶
func ParseForwarded(header string) (fw ForwardedHeader, err error)
ParseForwarded parses a Forwarded header and returns all passed directives within a forwarded map.
type Handler ¶
func MultiHandler ¶
MultiHandler creates a handler that executes all passed handlers one by one until one of them successfully processes the request.
If a listed handler returns an error, the overall handle operation stops and returns the error; it does not continue down the list.
type HandlerFunc ¶
HandlerFunc is a function adapter to allow use of ordinary functions as request handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.
func TimeoutHandler ¶
func TimeoutHandler(h Handler, t time.Duration) HandlerFunc
TimeoutHandler is a handler that limits the handler execution by the specified timeout. Wrapped handler must implement context cancellation.
It adds a timeout to the passed context and then executes a wrapped handler instance.
type ListenConfig ¶
type Listener ¶
type Listener interface {
ListenAndServe() error
Shutdowner
}
Server describes an interface to start and terminate a server.
func ListenHTTP ¶
func ListenHTTP(lc ListenConfig, h Handler) Listener
func ListenTCP ¶
func ListenTCP(lc ListenConfig, h Handler) Listener
func ListenUDP ¶
func ListenUDP(lc ListenConfig, h Handler) Listener
type Record ¶
type Record struct {
ID uint64 `json:"id"`
ZoneName string `json:"zoneName"`
TTL uint `json:"ttl"`
Name string `json:"name"`
Class *string `json:"class"`
Type string `json:"type"`
Data string `json:"data"`
Priority *string `json:"priority"`
CreatedAt int64 `json:"createdAt"`
UpdatedAt int64 `json:"updatedAt"`
}
func NewRecord ¶
func NewRecord(id uint64, input RecordInput) *Record
type RecordInput ¶
type Request ¶
type Request struct {
// ID is a unique identifier of the request. It's the same as DNS
// request identifier.
ID int64
// RequestURI is a path where request was submitted.
//
// For some applications it is usefull to extract parameters from
// the URL. This URL will be copied to each plugin.
RequestURI string
Header http.Header
Body dns.Msg
// At is a request submission timestamp.
At time.Time
}
func NewRequest ¶
func ReadRequest ¶
ReadRequest reads and parses an incoming request from r.
ReadRequst is a low-level function and should only be used for specialized applications; most code should use Listener to read request and handle them via Handler interface.
func (*Request) Forward ¶
Forward sets the "Forwarded" header defined in RFC 7239, section 4. This is used to pass local and remote address to the processing plugins.
type ResolverConfig ¶
type ResolverConfig struct {
// Name of the command used to execute the resolver.
Name string `hcl:"resolver,label"`
// Options is a list of additional options to execute the resolver.
Options cty.Value `hcl:"options,optional"`
Preload bool `hcl:"preload,optional"`
// Processes is a number of processes to start for handling requests.
// Default value is 1.
Processes int `hcl:"processes,optional"`
// MaxIdle is a maximum client requests waiting for processing.
// Default value is 1024.
MaxIdle int `hcl:"maxidle,optional"`
}
ResolverConfig is a configuration of a single resolver.
type Response ¶
type Response struct {
ID int64
// StatusCode is numerical status of the HTTP response, e.g. 200.
StatusCode int
// Header maps HTTP header keys to values. Keys in the map are
// canonicalized (see http.CanonicalHeaderKey).
Header http.Header
// Body respresents DNS response.
Body dns.Msg
}
func NewResponse ¶
func ReadResponse ¶
ReadResponse reads and returns HTTP response with encapsulated DNS response from r.
type ServerConfig ¶
type ServerConfig struct {
// ResolverDirectory sets the root directory for resolvers, when
// specified server searches the executable in the given path,
// otherwise a current directory will be used.
ResolverDirectory string `hcl:"resolver_directory,optional"`
// Listen defines an IP address and port used to listen to
//
// Examples:
//
// listen = ":5353"
// listen = "0.0.0.0:53"
Listen string `hcl:"listen,optional"`
// Proto specifies the protocol that will be used for communication
// with remotes queriers.
//
// Examples:
//
// proto = "udp"
// proto = "tcp"
Proto string `hcl:"proto,optional"`
// Maximum number of concurrent connection, zero is no limit.
//
// Example:
//
// max_conns = 512
MaxConns int `hcl:"max_conns,optional"`
// RequestTimeout is an optional maximum time for processing each request
// by a single resolver.
RequestTimeout string `hcl:"request_timeout,optional"`
// Resolvers is a sequence of resolution plugins that are sequentially
// polled in order to retrieve a response on the processing request.
//
// Each server starts resolvers isolated from other servers.
Resolvers []ResolverConfig `hcl:"resolver,block"`
}
ServerConfig is a configuration for a single server instance.
type ShutdownFunc ¶
ShutdownFunc tells a handler to terminate its work. ShutdownFunc waits for the work to stop. A ShutdownFunc may be called by multiple goroutines simultaneously.
func MultiShutdown ¶
func MultiShutdown(ss ...Shutdowner) ShutdownFunc