mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-11-23 11:49:19 +01:00
30 lines
549 B
Go
30 lines
549 B
Go
|
package util
|
||
|
|
||
|
import (
|
||
|
"math/rand"
|
||
|
"os"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
randomStringCharset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
random = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||
|
)
|
||
|
|
||
|
func FileExists(filename string) bool {
|
||
|
stat, _ := os.Stat(filename)
|
||
|
return stat != nil
|
||
|
}
|
||
|
|
||
|
// RandomString returns a random string with a given length
|
||
|
func RandomString(length int) string {
|
||
|
b := make([]byte, length)
|
||
|
for i := range b {
|
||
|
b[i] = randomStringCharset[random.Intn(len(randomStringCharset))]
|
||
|
}
|
||
|
return string(b)
|
||
|
}
|