1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00
pasty/internal/utils/random_string.go
Lukas Schulte Pelkum 99504e0bba
Implement API v2 (#13)
* Add documentation notice

* Rename the deletion token to modification token

* Implement API basics

* Implement paste modification endpoint (#10)

* Implement paste metadata

* Implement report webhook support

* Document API

* Document paste entity

* Update syntax highlighting types (js -> jsonc)

* Update migrator
2021-07-22 22:26:21 +02:00

20 lines
485 B
Go

package utils
import (
"math/rand"
"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 {
rand.Seed(time.Now().UnixNano())
bytes := make([]byte, length)
for i := range bytes {
bytes[i] = stringContents[rand.Int63()%int64(len(stringContents))]
}
return string(bytes)
}