This change is an attempt to handle gosimple linter finfings in order to make the code easier to follow. It includes the following changes: - use strings.Contains instead of strings.Index != -1 - use time.Since which is the standard library helper. See https://github.com/golang/go/blob/go1.15.2/src/time/time.go#L866-L867 - remove unneeded return statements at the end of methods - preallocate maps when their capacity is known - avoid underscoring values when they can be omitted - avoid fmt.Sprintf() calls when the only argument is already a string Signed-off-by: Miguel Ángel Jimeno <miguelangel4b@gmail.com>
42 lines
880 B
Go
42 lines
880 B
Go
package ffuf
|
|
|
|
import (
|
|
"math/rand"
|
|
"os"
|
|
)
|
|
|
|
//used for random string generation in calibration function
|
|
var chars = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
|
|
//RandomString returns a random string of length of parameter n
|
|
func RandomString(n int) string {
|
|
s := make([]rune, n)
|
|
for i := range s {
|
|
s[i] = chars[rand.Intn(len(chars))]
|
|
}
|
|
return string(s)
|
|
}
|
|
|
|
//UniqStringSlice returns an unordered slice of unique strings. The duplicates are dropped
|
|
func UniqStringSlice(inslice []string) []string {
|
|
found := map[string]bool{}
|
|
|
|
for _, v := range inslice {
|
|
found[v] = true
|
|
}
|
|
ret := []string{}
|
|
for k := range found {
|
|
ret = append(ret, k)
|
|
}
|
|
return ret
|
|
}
|
|
|
|
//FileExists checks if the filepath exists and is not a directory
|
|
func FileExists(path string) bool {
|
|
md, err := os.Stat(path)
|
|
if os.IsNotExist(err) {
|
|
return false
|
|
}
|
|
return !md.IsDir()
|
|
}
|