mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-04 02:01:07 +01:00 
			
		
		
		
	This was done anyway, but only deep in the functions, just do this everywhere; allows for shorter code and request.Request allows for caching as well. Cleanups, make it more Go like. * remove unneeded switches * remove testdir (why was this there??) * simplify the logic * remove unneeded variables * put short functions on a single line * fix documentation. * spin off wire funcs in wire.go, make them functions. Signed-off-by: Miek Gieben <miek@miek.nl>
		
			
				
	
	
		
			47 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package rewrite
 | 
						|
 | 
						|
import (
 | 
						|
	"fmt"
 | 
						|
	"strings"
 | 
						|
 | 
						|
	"github.com/coredns/coredns/request"
 | 
						|
 | 
						|
	"github.com/miekg/dns"
 | 
						|
)
 | 
						|
 | 
						|
type classRule struct {
 | 
						|
	fromClass  uint16
 | 
						|
	toClass    uint16
 | 
						|
	NextAction string
 | 
						|
}
 | 
						|
 | 
						|
// newClassRule creates a class matching rule
 | 
						|
func newClassRule(nextAction string, args ...string) (Rule, error) {
 | 
						|
	var from, to uint16
 | 
						|
	var ok bool
 | 
						|
	if from, ok = dns.StringToClass[strings.ToUpper(args[0])]; !ok {
 | 
						|
		return nil, fmt.Errorf("invalid class %q", strings.ToUpper(args[0]))
 | 
						|
	}
 | 
						|
	if to, ok = dns.StringToClass[strings.ToUpper(args[1])]; !ok {
 | 
						|
		return nil, fmt.Errorf("invalid class %q", strings.ToUpper(args[1]))
 | 
						|
	}
 | 
						|
	return &classRule{from, to, nextAction}, nil
 | 
						|
}
 | 
						|
 | 
						|
// Rewrite rewrites the the current request.
 | 
						|
func (rule *classRule) Rewrite(state request.Request) Result {
 | 
						|
	if rule.fromClass > 0 && rule.toClass > 0 {
 | 
						|
		if state.Req.Question[0].Qclass == rule.fromClass {
 | 
						|
			state.Req.Question[0].Qclass = rule.toClass
 | 
						|
			return RewriteDone
 | 
						|
		}
 | 
						|
	}
 | 
						|
	return RewriteIgnored
 | 
						|
}
 | 
						|
 | 
						|
// Mode returns the processing mode.
 | 
						|
func (rule *classRule) Mode() string { return rule.NextAction }
 | 
						|
 | 
						|
// GetResponseRule return a rule to rewrite the response with. Currently not implemented.
 | 
						|
func (rule *classRule) GetResponseRule() ResponseRule { return ResponseRule{} }
 |