mirror of
https://github.com/lus/pasty.git
synced 2023-08-10 21:13:09 +03:00
Add option to define ID and modification token generation characters (#17)
This commit is contained in:
@@ -5,15 +5,12 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// stringContents holds the chars a random string can contain
|
||||
const stringContents = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
|
||||
// RandomString returns a random string with the given length
|
||||
func RandomString(length int) string {
|
||||
func RandomString(characters string, length int) string {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
bytes := make([]byte, length)
|
||||
for i := range bytes {
|
||||
bytes[i] = stringContents[rand.Int63()%int64(len(stringContents))]
|
||||
bytes[i] = characters[rand.Int63()%int64(len(characters))]
|
||||
}
|
||||
return string(bytes)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user