aboutsummaryrefslogtreecommitdiff
path: root/plugin/rewrite/class.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-07-02 15:39:50 +0100
committerGravatar Yong Tang <yong.tang.github@outlook.com> 2018-07-02 07:39:50 -0700
commit6dd2cf8c4b30822f1d718fbef728f6856628a3df (patch)
treefce20dc6ee9a9400130c0c82292ba470be82fe7b /plugin/rewrite/class.go
parent1abecf99d97270075731b9f7cc01c9e2b687d570 (diff)
downloadcoredns-6dd2cf8c4b30822f1d718fbef728f6856628a3df.tar.gz
coredns-6dd2cf8c4b30822f1d718fbef728f6856628a3df.tar.zst
coredns-6dd2cf8c4b30822f1d718fbef728f6856628a3df.zip
plugin/rewrite: use request.Request and other cleanups (#1920)
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>
Diffstat (limited to 'plugin/rewrite/class.go')
-rw-r--r--plugin/rewrite/class.go18
1 files changed, 8 insertions, 10 deletions
diff --git a/plugin/rewrite/class.go b/plugin/rewrite/class.go
index 2e54f515c..d72557884 100644
--- a/plugin/rewrite/class.go
+++ b/plugin/rewrite/class.go
@@ -4,6 +4,8 @@ import (
"fmt"
"strings"
+ "github.com/coredns/coredns/request"
+
"github.com/miekg/dns"
)
@@ -27,22 +29,18 @@ func newClassRule(nextAction string, args ...string) (Rule, error) {
}
// Rewrite rewrites the the current request.
-func (rule *classRule) Rewrite(w dns.ResponseWriter, r *dns.Msg) Result {
+func (rule *classRule) Rewrite(state request.Request) Result {
if rule.fromClass > 0 && rule.toClass > 0 {
- if r.Question[0].Qclass == rule.fromClass {
- r.Question[0].Qclass = rule.toClass
+ 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
-}
+// 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{}
-}
+func (rule *classRule) GetResponseRule() ResponseRule { return ResponseRule{} }