Codebase list ffuf / debian/1.1.0-1 pkg / ffuf / util.go
debian/1.1.0-1

Tree @debian/1.1.0-1 (Download .tar.gz)

util.go @debian/1.1.0-1raw · history · blame

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()
}