mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-03 18:53:13 -05:00 
			
		
		
		
	This revert 17d807f0 and re-adds the metadata plugin as a plugin that
just sets a label to a value function.
Add package documentation on how to use the metadata package. Make it
clear that any caching is up to the Func implemented.
There are now - no in tree users. We could add the request metadata by
default under names that copy request.Request, i.e
request/ip - remote IP
request/port - remote port
Variables.go has been deleted.
Signed-off-by: Miek Gieben <miek@miek.nl>
		
	
		
			
				
	
	
		
			40 lines
		
	
	
		
			953 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			953 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package metadata
 | 
						|
 | 
						|
import (
 | 
						|
	"context"
 | 
						|
 | 
						|
	"github.com/coredns/coredns/plugin"
 | 
						|
	"github.com/coredns/coredns/request"
 | 
						|
 | 
						|
	"github.com/miekg/dns"
 | 
						|
)
 | 
						|
 | 
						|
// Metadata implements collecting metadata information from all plugins that
 | 
						|
// implement the Provider interface.
 | 
						|
type Metadata struct {
 | 
						|
	Zones     []string
 | 
						|
	Providers []Provider
 | 
						|
	Next      plugin.Handler
 | 
						|
}
 | 
						|
 | 
						|
// Name implements the Handler interface.
 | 
						|
func (m *Metadata) Name() string { return "metadata" }
 | 
						|
 | 
						|
// ServeDNS implements the plugin.Handler interface.
 | 
						|
func (m *Metadata) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
 | 
						|
 | 
						|
	ctx = context.WithValue(ctx, key{}, md{})
 | 
						|
 | 
						|
	state := request.Request{W: w, Req: r}
 | 
						|
	if plugin.Zones(m.Zones).Matches(state.Name()) != "" {
 | 
						|
		// Go through all Providers and collect metadata.
 | 
						|
		for _, p := range m.Providers {
 | 
						|
			ctx = p.Metadata(ctx, state)
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	rcode, err := plugin.NextOrFailure(m.Name(), m.Next, ctx, w, r)
 | 
						|
 | 
						|
	return rcode, err
 | 
						|
}
 |