mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 16:54:15 -04:00
Cleanup: put middleware helper functions in pkgs (#245)
Move all (almost all) Go files in middleware into their own packages. This makes for better naming and discoverability. Lot of changes elsewhere to make this change. The middleware.State was renamed to request.Request which is better, but still does not cover all use-cases. It was also moved out middleware because it is used by `dnsserver` as well. A pkg/dnsutil packages was added for shared, handy, dns util functions. All normalize functions are now put in normalize.go
This commit is contained in:
@@ -2,16 +2,17 @@ package kubernetes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/miekg/coredns/middleware"
|
||||
"github.com/miekg/coredns/middleware/pkg/dnsutil"
|
||||
"github.com/miekg/coredns/request"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
state := middleware.State{W: w, Req: r}
|
||||
state := request.Request{W: w, Req: r}
|
||||
if state.QClass() != dns.ClassINET {
|
||||
return dns.RcodeServerFailure, fmt.Errorf("can only deal with ClassINET")
|
||||
}
|
||||
@@ -21,8 +22,8 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
|
||||
m.Authoritative, m.RecursionAvailable, m.Compress = true, true, true
|
||||
|
||||
// TODO: find an alternative to this block
|
||||
if strings.HasSuffix(state.Name(), arpaSuffix) {
|
||||
ip, _ := extractIP(state.Name())
|
||||
ip := dnsutil.ExtractAddressFromReverse(state.Name())
|
||||
if ip != "" {
|
||||
records := k.getServiceRecordForIP(ip, state.Name())
|
||||
if len(records) > 0 {
|
||||
srvPTR := &records[0]
|
||||
@@ -100,7 +101,7 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
|
||||
}
|
||||
|
||||
// NoData write a nodata response to the client.
|
||||
func (k Kubernetes) Err(zone string, rcode int, state middleware.State) (int, error) {
|
||||
func (k Kubernetes) Err(zone string, rcode int, state request.Request) (int, error) {
|
||||
m := new(dns.Msg)
|
||||
m.SetRcode(state.Req, rcode)
|
||||
m.Ns = []dns.RR{k.SOA(zone, state)}
|
||||
|
||||
Reference in New Issue
Block a user