aboutsummaryrefslogtreecommitdiff
path: root/server/zones.go
blob: 6a5a7a938844d14a1051d1e5cd1e7f38da990b61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package server

import "github.com/miekg/coredns/middleware"

// zone represents a DNS zone. While a Server
// is what actually binds to the address, a user may want to serve
// multiple zones on a single address, and this is what a
// zone allows us to do.
type zone struct {
	config Config
	stack  middleware.Handler
}

// buildStack builds the server's middleware stack based
// on its config. This method should be called last before
// ListenAndServe begins.
func (z *zone) buildStack() error {
	z.compile(z.config.Middleware)
	return nil
}

// compile is an elegant alternative to nesting middleware function
// calls like handler1(handler2(handler3(finalHandler))).
func (z *zone) compile(layers []middleware.Middleware) {
	for i := len(layers) - 1; i >= 0; i-- {
		z.stack = layers[i](z.stack)
	}
}