Merge pull request #6243 from tongjicoder/dev

refactor: use slices.Contains to simplify code
This commit is contained in:
Dogan Can Bakir
2025-05-27 15:48:20 +03:00
committed by GitHub
5 changed files with 11 additions and 30 deletions

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"io"
"path"
"slices"
"strings"
"github.com/aws/aws-sdk-go-v2/aws"
@@ -140,10 +141,8 @@ func (c Catalog) ResolvePath(templateName, second string) (string, error) {
}
// check if templateName is already an absolute path to c key
for _, key := range keys {
if key == templateName {
return templateName, nil
}
if slices.Contains(keys, templateName) {
return templateName, nil
}
return "", fmt.Errorf("no such path found: %s%s for keys: %v", second, templateName, keys)

View File

@@ -3,6 +3,7 @@ package aws
import (
"io"
"reflect"
"slices"
"strings"
"testing"
@@ -250,13 +251,7 @@ func (m mocks3svc) getAllKeys() ([]string, error) {
}
func (m mocks3svc) downloadKey(name string) (io.ReadCloser, error) {
found := false
for _, key := range m.keys {
if key == name {
found = true
break
}
}
found := slices.Contains(m.keys, name)
if !found {
return nil, errors.New("key not found")
}

View File

@@ -7,6 +7,7 @@ import (
"log"
"os"
"path/filepath"
"slices"
"strings"
"github.com/projectdiscovery/goflags"
@@ -334,12 +335,7 @@ func (c *Config) copyIgnoreFile() {
// this could be a feature specific to debugging like PPROF or printing stats
// of max host error etc
func (c *Config) IsDebugArgEnabled(arg string) bool {
for _, v := range c.debugArgs {
if v == arg {
return true
}
}
return false
return slices.Contains(c.debugArgs, arg)
}
// parseDebugArgs from string

View File

@@ -2,6 +2,7 @@ package openapi
import (
"fmt"
"slices"
"github.com/getkin/kin-openapi/openapi3"
"github.com/pkg/errors"
@@ -84,13 +85,7 @@ func excludeFromMode(schema *openapi3.Schema) bool {
// isRequired checks whether a key is actually required.
func isRequired(schema *openapi3.Schema, key string) bool {
for _, req := range schema.Required {
if req == key {
return true
}
}
return false
return slices.Contains(schema.Required, key)
}
type cachedSchema struct {

View File

@@ -2,6 +2,7 @@ package http
import (
"regexp"
"slices"
)
var (
@@ -32,10 +33,5 @@ func (request *Request) NeedsRequestCondition() bool {
}
func checkRequestConditionExpressions(expressions ...string) bool {
for _, expression := range expressions {
if reRequestCondition.MatchString(expression) {
return true
}
}
return false
return slices.ContainsFunc(expressions, reRequestCondition.MatchString)
}