1
1
Fork 0
mirror of https://github.com/OJ/gobuster.git synced 2024-05-06 23:26:02 +02:00
gobuster/helper/helper.go
Christian Mehlmauer 0a0cab949f
Dev Updates (#305)
* retry on timeout
* Google Cloud Bucket enumeration
* colors in output
* goreleaser
* fix nil reference errors
2022-10-08 18:41:25 +02:00

66 lines
1.4 KiB
Go

package helper
import (
"fmt"
"strconv"
"strings"
"github.com/OJ/gobuster/v3/libgobuster"
)
// ParseExtensions parses the extensions provided as a comma separated list
func ParseExtensions(extensions string) (libgobuster.Set[string], error) {
ret := libgobuster.NewSet[string]()
if extensions == "" {
return ret, nil
}
for _, e := range strings.Split(extensions, ",") {
e = strings.TrimSpace(e)
// remove leading . from extensions
ret.Add(strings.TrimPrefix(e, "."))
}
return ret, nil
}
// ParseCommaSeparatedInt parses the status codes provided as a comma separated list
func ParseCommaSeparatedInt(inputString string) (libgobuster.Set[int], error) {
ret := libgobuster.NewSet[int]()
if inputString == "" {
return ret, nil
}
for _, c := range strings.Split(inputString, ",") {
c = strings.TrimSpace(c)
i, err := strconv.Atoi(c)
if err != nil {
return libgobuster.NewSet[int](), fmt.Errorf("invalid string given: %s", c)
}
ret.Add(i)
}
return ret, nil
}
// SliceContains checks if an integer slice contains a specific value
func SliceContains(s []int, e int) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
// JoinIntSlice joins an int slice by ,
func JoinIntSlice(s []int) string {
valuesText := make([]string, len(s))
for i, number := range s {
text := strconv.Itoa(number)
valuesText[i] = text
}
result := strings.Join(valuesText, ",")
return result
}