mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
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:
@@ -4,6 +4,8 @@ package log
|
||||
import (
|
||||
"log"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/miekg/coredns/middleware"
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
@@ -15,7 +17,7 @@ type Logger struct {
|
||||
ErrorFunc func(dns.ResponseWriter, *dns.Msg, int) // failover error handler
|
||||
}
|
||||
|
||||
func (l Logger) ServeDNS(w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
func (l Logger) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
for _, rule := range l.Rules {
|
||||
/*
|
||||
if middleware.Path(r.URL.Path).Matches(rule.PathScope) {
|
||||
@@ -40,7 +42,7 @@ func (l Logger) ServeDNS(w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
*/
|
||||
rule = rule
|
||||
}
|
||||
return l.Next.ServeDNS(w, r)
|
||||
return l.Next.ServeDNS(ctx, w, r)
|
||||
}
|
||||
|
||||
// Rule configures the logging middleware.
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
/*
|
||||
type erroringMiddleware struct{}
|
||||
|
||||
func (erroringMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
func (erroringMiddleware) ServeDNS(w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
return http.StatusNotFound, nil
|
||||
}
|
||||
|
||||
@@ -46,3 +38,4 @@ func TestLoggedStatus(t *testing.T) {
|
||||
t.Error("Expected 404 to be logged. Logged string -", logged)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user