chore(lint): modernize Go (#7536)

Use modern Go constructs through the modernize analyzer from the
golang.org/x/tools package.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
This commit is contained in:
Ville Vesilehto
2025-09-10 23:08:27 +03:00
committed by GitHub
parent afdd41a266
commit 39abf5aeba
48 changed files with 150 additions and 193 deletions

View File

@@ -40,8 +40,8 @@ func (r *cnameTargetRule) getFromAndToTarget(inputCName string) (from string, to
case ExactMatch:
return r.paramFromTarget, r.paramToTarget
case PrefixMatch:
if strings.HasPrefix(inputCName, r.paramFromTarget) {
return inputCName, r.paramToTarget + strings.TrimPrefix(inputCName, r.paramFromTarget)
if after, ok := strings.CutPrefix(inputCName, r.paramFromTarget); ok {
return inputCName, r.paramToTarget + after
}
case SuffixMatch:
if strings.HasSuffix(inputCName, r.paramFromTarget) {

View File

@@ -203,8 +203,8 @@ func newPrefixNameRule(nextAction string, auto bool, prefix, replacement string,
}
func (rule *prefixNameRule) Rewrite(ctx context.Context, state request.Request) (ResponseRules, Result) {
if strings.HasPrefix(state.Name(), rule.prefix) {
state.Req.Question[0].Name = rule.replacement + strings.TrimPrefix(state.Name(), rule.prefix)
if after, ok := strings.CutPrefix(state.Name(), rule.prefix); ok {
state.Req.Question[0].Name = rule.replacement + after
return rule.responseRuleFor(state)
}
return nil, RewriteIgnored

View File

@@ -33,8 +33,7 @@ func TestRewriteIllegalName(t *testing.T) {
}
func TestRewriteNamePrefixSuffix(t *testing.T) {
ctx, close := context.WithCancel(context.TODO())
defer close()
ctx := t.Context()
tests := []struct {
next string
@@ -75,8 +74,7 @@ func TestRewriteNamePrefixSuffix(t *testing.T) {
}
func TestRewriteNameNoRewrite(t *testing.T) {
ctx, close := context.WithCancel(context.TODO())
defer close()
ctx := t.Context()
tests := []struct {
next string
@@ -117,8 +115,7 @@ func TestRewriteNameNoRewrite(t *testing.T) {
}
func TestRewriteNamePrefixSuffixNoAutoAnswer(t *testing.T) {
ctx, close := context.WithCancel(context.TODO())
defer close()
ctx := t.Context()
tests := []struct {
next string
@@ -159,8 +156,7 @@ func TestRewriteNamePrefixSuffixNoAutoAnswer(t *testing.T) {
}
func TestRewriteNamePrefixSuffixAutoAnswer(t *testing.T) {
ctx, close := context.WithCancel(context.TODO())
defer close()
ctx := t.Context()
tests := []struct {
next string
@@ -207,8 +203,7 @@ func TestRewriteNamePrefixSuffixAutoAnswer(t *testing.T) {
}
func TestRewriteNameExactAnswer(t *testing.T) {
ctx, close := context.WithCancel(context.TODO())
defer close()
ctx := t.Context()
tests := []struct {
next string
@@ -255,8 +250,7 @@ func TestRewriteNameExactAnswer(t *testing.T) {
}
func TestRewriteNameRegexAnswer(t *testing.T) {
ctx, close := context.WithCancel(context.TODO())
defer close()
ctx := t.Context()
tests := []struct {
next string