mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 04:55:28 +00:00
refactor: use slices.Contains to simplify code
Signed-off-by: tongjicoder <tongjicoder@icloud.com>
This commit is contained in:
parent
8a13639b62
commit
3be29abfc9
@ -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)
|
||||
|
||||
@ -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")
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user