Documentation ¶
Index ¶
- Constants
- Variables
- func Classic(ctx context.Context, h Handler) dns.Handler
- func Exists(rrSet []dns.RR, t uint16) bool
- func ExistsAny(rrSet []dns.RR, t ...uint16) bool
- func First(rrSet []dns.RR, t uint16) int
- func FirstAny(rrSet []dns.RR, t ...uint16) int
- func FurtherRequest(w ResponseWriter, req *Request, qname string, qtype uint16, h Handler) dns.Msg
- type Answer
- type CheckRedirect
- type Class
- type Handler
- func BasicHandler(h Handler) Handler
- func ChainHandler(h Handler, middlewares ...Middleware) Handler
- func CnameHandler(h Handler) Handler
- func ExtraHandler(h Handler) Handler
- func MultiHandler(m ...Handler) Handler
- func NsHandler(h Handler) Handler
- func NsecHandler(h Handler) Handler
- func OptHandler(h Handler) Handler
- func PanicHandler(h Handler) Handler
- func ParamsHandler(h Handler, params Params) Handler
- func RefusedHandler(h Handler) Handler
- func WildcardHandler(h Handler) Handler
- type HandlerFunc
- type Middleware
- type Param
- type Params
- type RcodeHandler
- type Request
- type ResponseWriter
- type Router
- func (r *Router) Handle(s string, handler Handler)
- func (r *Router) HandleFunc(s string, handlerFunc HandlerFunc)
- func (r *Router) HandleZone(f io.Reader, origin, filename string)
- func (r *Router) HandleZoneFile(origin, filename string)
- func (r *Router) Lookup(name string, qclass uint16) Class
- func (r *Router) ServeDNS(resp ResponseWriter, req *Request)
- type Stub
Constants ¶
const ClassContextKey classContextKeyType = 1
ClassContextKey is used to get Class instance from Request context.
Variables ¶
var ( // NoErrorHandler responses dns.RcodeSuccess. NoErrorHandler = RcodeHandler(dns.RcodeSuccess) // NameErrorHandler responses dns.RcodeNameError. NameErrorHandler = RcodeHandler(dns.RcodeNameError) )
var ( // DefaultScheme consists of middlewares serving as a complete stub name server. DefaultScheme = []Middleware{ PanicHandler, RefusedHandler, OptHandler, WildcardHandler, NsecHandler, NsHandler, ExtraHandler, CnameHandler, BasicHandler, } // SimpleScheme consists of essential middlewares without filling out AUTHORITY and ADDITIONAL sections. // This scheme is faster (2x bench of DefaultScheme) and suitable for most of ordinary situations. SimpleScheme = []Middleware{ PanicHandler, RefusedHandler, OptHandler, WildcardHandler, CnameHandler, BasicHandler, } )
Functions ¶
func FirstAny ¶
FirstAny returns the index of the first element of any of given qtypes. If not found, returns -1.
func FurtherRequest ¶
FurtherRequest is a helper function to execute another query within current context.
Types ¶
type Answer ¶
Answer is a handler which writes the RR into ANSWER section.
func (Answer) ServeDNS ¶
func (a Answer) ServeDNS(w ResponseWriter, r *Request)
ServeDNS implements Handler interface.
type CheckRedirect ¶
type CheckRedirect interface {
Qtype() uint16
}
CheckRedirect is useful for checking type assertion on a Handle that returned from a Search if which occurs DNAME or CNAME redirection.
type Class ¶
type Class interface { NextSecure(nsecType uint16) (nsec Class) Search(qtype uint16) (h Handler) Stub() (stub Stub) Zone() (zone Class, delegated bool) }
A Class is acquired from a Stub via an arbitrary name with a class.
type Handler ¶
type Handler interface {
ServeDNS(ResponseWriter, *Request)
}
A Handler responds to a DNS request.
func BasicHandler ¶
BasicHandler is a middleware filling out essential answer section.
func ChainHandler ¶
func ChainHandler(h Handler, middlewares ...Middleware) Handler
ChainHandler applies middlewares on given handler.
func CnameHandler ¶
CnameHandler is a middleware following the query on canonical name.
func ExtraHandler ¶
ExtraHandler is a middleware filling out additional A/AAAA records for target names.
func MultiHandler ¶
MultiHandler merges multiple handlers into a single one.
func NsecHandler ¶
NsecHandler returns a middleware that filling out denial-of-existence records.
func OptHandler ¶
OptHandler is a middleware filling out OPT records if request is compatible with EDNS0.
func PanicHandler ¶
PanicHandler is a middleware filling out an extra TXT record from a recovered panic, as well as setting SERVFAIL.
func ParamsHandler ¶
ParamsHandler fills the params into request context.
func RefusedHandler ¶
RefusedHandler is a middleware setting REFUSED code if no ANSWERs or NSs either.
func WildcardHandler ¶
WildcardHandler is a middleware expanding wildcard.
type HandlerFunc ¶
type HandlerFunc func(ResponseWriter, *Request)
The HandlerFunc type is an adapter to allow the use of ordinary functions as DNS handlers.
func (HandlerFunc) ServeDNS ¶
func (f HandlerFunc) ServeDNS(w ResponseWriter, r *Request)
ServeDNS implements Handler interface.
type Params ¶
type Params []Param
Params is a Param-slice, as returned by the router. The slice is ordered, the first domain parameter is also the first slice value. It is therefore safe to read values by the index.
type RcodeHandler ¶
type RcodeHandler int
RcodeHandler writes an arbitrary response code.
func (RcodeHandler) ServeDNS ¶
func (e RcodeHandler) ServeDNS(w ResponseWriter, r *Request)
ServeDNS implements Handler interface.
type Request ¶
A Request represents a DNS request received by a server.
func NewRequest ¶
NewRequest makes a question request.
type ResponseWriter ¶
A ResponseWriter interface is used by a DNS handler to construct an DNS response.
func NewResponseWriter ¶
func NewResponseWriter() ResponseWriter
NewResponseWriter creates a response writer.
type Router ¶
type Router struct { // Configurable middleware that chaining with the Router. // If it is nil, then uses DefaultScheme. Middleware []Middleware // contains filtered or unexported fields }
Router is a dns Handler which can be used to dispatch requests to different handler functions via configurable routes.
func (*Router) Handle ¶
Handle registers a new request handler with a routing pattern, any string that can pass into dns.NewRR is legal to use in here. Only a domain that beginning with a single asterisk (*) is treated as wildcard (https://tools.ietf.org/html/rfc4592), in other cases, wildcard labels or named parameters are treated as same as path components used in httprouter (https://github.com/julienschmidt/httprouter). If the handler is nil then defaults to write the resulted record into answer section. Please pay attention that Handle won't check if the given string contains an actual record data, e.g. "github.com A" is legal to pass to Handle, so calling Handle("github.com A", nil) causes a strange RR "github.com. 3600 IN A " in ANSWER section.
func (*Router) HandleFunc ¶
func (r *Router) HandleFunc(s string, handlerFunc HandlerFunc)
HandleFunc registers a new request handler function with a routing pattern.
func (*Router) HandleZone ¶
HandleZone loads a zone reader.
func (*Router) HandleZoneFile ¶
HandleZoneFile loads a zone file.
func (*Router) ServeDNS ¶
func (r *Router) ServeDNS(resp ResponseWriter, req *Request)
ServeDNS implements Handler interface.