Use context.Context

Rename the old Context to State and use context.Context in the
middleware for intra-middleware communication and more.
This commit is contained in:
Miek Gieben
2016-03-19 07:18:57 +00:00
parent 523cc0a0fd
commit f907311cdf
27 changed files with 358 additions and 919 deletions

View File

@@ -4,15 +4,17 @@ import (
"strconv"
"time"
"golang.org/x/net/context"
"github.com/miekg/coredns/middleware"
"github.com/miekg/dns"
)
func (m *Metrics) ServeDNS(w dns.ResponseWriter, r *dns.Msg) (int, error) {
context := middleware.Context{W: w, Req: r}
func (m *Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
state := middleware.State{W: w, Req: r}
qname := context.Name()
qtype := context.Type()
qname := state.Name()
qtype := state.Type()
zone := middleware.Zones(m.ZoneNames).Matches(qname)
if zone == "" {
zone = "."
@@ -20,7 +22,7 @@ func (m *Metrics) ServeDNS(w dns.ResponseWriter, r *dns.Msg) (int, error) {
// Record response to get status code and size of the reply.
rw := middleware.NewResponseRecorder(w)
status, err := m.Next.ServeDNS(rw, r)
status, err := m.Next.ServeDNS(ctx, rw, r)
requestCount.WithLabelValues(zone, qtype).Inc()
requestDuration.WithLabelValues(zone).Observe(float64(time.Since(rw.Start()) / time.Second))