auto go fmt

This commit is contained in:
coredns-auto-go-fmt[bot] 2021-02-24 10:22:15 +00:00
parent d07a3ac6c2
commit ff9b4bcb98
4 changed files with 25 additions and 23 deletions

View file

@ -140,7 +140,7 @@ func newNameRule(nextAction string, args ...string) (Rule, error) {
}
//if len(args) > 3 && len(args) != 7 {
if len(args) > 3 && (len(args) - 3) % 4 != 0 {
if len(args) > 3 && (len(args)-3)%4 != 0 {
return nil, fmt.Errorf("response rewrites must consist only of a name rule with 3 arguments and one or more answer rules with 3 arguments each")
}
@ -199,7 +199,7 @@ func newNameRule(nextAction string, args ...string) (Rule, error) {
}
}
//if len(args) == 7 {
if (len(args) - 3) % 4 == 0 {
if (len(args)-3)%4 == 0 {
if matchType == RegexMatch {
rewriteQuestionFromPattern, err := isValidRegexPattern(rewriteQuestionFrom, rewriteQuestionTo)
if err != nil {
@ -209,9 +209,9 @@ func newNameRule(nextAction string, args ...string) (Rule, error) {
responseRuleCount := (len(args) - 3) / 4
responseRules := make([]ResponseRule, responseRuleCount)
for i := 0; i < responseRuleCount; i ++ {
for i := 0; i < responseRuleCount; i++ {
startIdx := 3 + (i * 4)
responseRule, err := newResponseRule(args[startIdx:startIdx + 4])
responseRule, err := newResponseRule(args[startIdx : startIdx+4])
if err != nil {
return nil, err
}
@ -231,7 +231,7 @@ func newNameRule(nextAction string, args ...string) (Rule, error) {
}
// newResponseRule creates a new "answer name" or "answer value" response rule.
func newResponseRule(args []string) (responseRule *ResponseRule, err error){
func newResponseRule(args []string) (responseRule *ResponseRule, err error) {
if args[0] != "answer" {
return nil, fmt.Errorf("exceeded the number of arguments for a regex name rule")
}
@ -266,7 +266,9 @@ func (rule *substringNameRule) Mode() string { return rule.NextAction }
func (rule *regexNameRule) Mode() string { return rule.NextAction }
// GetResponseRules returns rules to rewrite the response with. Currently not implemented.
func (rule *exactNameRule) GetResponseRules() []ResponseRule { return []ResponseRule{rule.ResponseRule} }
func (rule *exactNameRule) GetResponseRules() []ResponseRule {
return []ResponseRule{rule.ResponseRule}
}
// GetResponseRules returns rules to rewrite the response with. Currently not implemented.
func (rule *prefixNameRule) GetResponseRules() []ResponseRule { return []ResponseRule{} }

View file

@ -60,12 +60,12 @@ func (r *ResponseReverter) WriteMsg(res1 *dns.Msg) error {
func rewriteResourceRecord(res *dns.Msg, rr dns.RR, r *ResponseReverter) {
var (
isNameRewritten bool
isTTLRewritten bool
isValueRewritten bool
name = rr.Header().Name
ttl = rr.Header().Ttl
value string
isNameRewritten bool
isTTLRewritten bool
isValueRewritten bool
name = rr.Header().Name
ttl = rr.Header().Ttl
value string
)
for _, rule := range r.ResponseRules {

View file

@ -77,7 +77,7 @@ var valueTests = []struct {
to string
toType uint16
noRevert bool
expectValue string
expectValue string
expectAnswerType uint16
expectAddlName string
}{

View file

@ -13,32 +13,32 @@ import (
)
type exactTTLRule struct {
NextAction string
From string
NextAction string
From string
ResponseRules []ResponseRule
}
type prefixTTLRule struct {
NextAction string
Prefix string
NextAction string
Prefix string
ResponseRules []ResponseRule
}
type suffixTTLRule struct {
NextAction string
Suffix string
NextAction string
Suffix string
ResponseRules []ResponseRule
}
type substringTTLRule struct {
NextAction string
Substring string
NextAction string
Substring string
ResponseRules []ResponseRule
}
type regexTTLRule struct {
NextAction string
Pattern *regexp.Regexp
NextAction string
Pattern *regexp.Regexp
ResponseRules []ResponseRule
}