Подготовить HY2XS к production-сборке
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package util
|
||||
|
||||
import "crypto/rand"
|
||||
|
||||
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
|
||||
func RandomString(length int) (string, error) {
|
||||
bytes := make([]byte, length)
|
||||
_, err := rand.Read(bytes)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for i := range bytes {
|
||||
bytes[i] = charset[int(bytes[i])%len(charset)]
|
||||
}
|
||||
|
||||
return string(bytes), nil
|
||||
}
|
||||
Reference in New Issue
Block a user