La context (#521)

* middleware/proxy: give Exchange a context

Make context.Context the first paramater in the Exchange method.
This is inline with all other query functions.

* up the version
This commit is contained in:
Miek Gieben
2017-02-11 16:56:04 +00:00
committed by GitHub
parent 5f6c7682be
commit a5f3cb5fe5
6 changed files with 11 additions and 6 deletions

View File

@@ -7,7 +7,7 @@ services:
language: go
go:
- 1.6
- 1.7
go_import_path: github.com/miekg/coredns

View File

@@ -1,6 +1,7 @@
package proxy
import (
"context"
"net"
"time"
@@ -24,7 +25,7 @@ func (d *dnsEx) OnShutdown(p *Proxy) error { return nil }
func (d *dnsEx) OnStartup(p *Proxy) error { return nil }
// Exchange implements the Exchanger interface.
func (d *dnsEx) Exchange(addr string, state request.Request) (*dns.Msg, error) {
func (d *dnsEx) Exchange(ctx context.Context, addr string, state request.Request) (*dns.Msg, error) {
co, err := net.DialTimeout(state.Proto(), addr, d.Timeout)
if err != nil {
return nil, err

View File

@@ -1,6 +1,8 @@
package proxy
import (
"context"
"github.com/miekg/coredns/request"
"github.com/miekg/dns"
)
@@ -8,7 +10,7 @@ import (
// Exchanger is an interface that specifies a type implementing a DNS resolver that
// can use whatever transport it likes.
type Exchanger interface {
Exchange(addr string, state request.Request) (*dns.Msg, error)
Exchange(ctx context.Context, addr string, state request.Request) (*dns.Msg, error)
Protocol() string
OnStartup(*Proxy) error

View File

@@ -1,6 +1,7 @@
package proxy
import (
"context"
"crypto/tls"
"encoding/json"
"fmt"
@@ -42,7 +43,7 @@ func newGoogle(endpoint string, bootstrap []string) *google {
return &google{client: client, endpoint: dns.Fqdn(endpoint), bootstrapProxy: boot, quit: make(chan bool)}
}
func (g *google) Exchange(addr string, state request.Request) (*dns.Msg, error) {
func (g *google) Exchange(ctx context.Context, addr string, state request.Request) (*dns.Msg, error) {
v := url.Values{}
v.Set("name", state.Name())

View File

@@ -3,6 +3,7 @@ package proxy
// functions other middleware might want to use to do lookup in the same style as the proxy.
import (
"context"
"sync/atomic"
"time"
@@ -91,7 +92,7 @@ func (p Proxy) lookup(state request.Request) (*dns.Msg, error) {
atomic.AddInt64(&host.Conns, 1)
reply, backendErr := upstream.Exchanger().Exchange(host.Name, state)
reply, backendErr := upstream.Exchanger().Exchange(context.TODO(), host.Name, state)
atomic.AddInt64(&host.Conns, -1)

View File

@@ -105,7 +105,7 @@ func (p Proxy) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
atomic.AddInt64(&host.Conns, 1)
reply, backendErr := upstream.Exchanger().Exchange(host.Name, state)
reply, backendErr := upstream.Exchanger().Exchange(ctx, host.Name, state)
atomic.AddInt64(&host.Conns, -1)