Commit 75c77df 1 parent 6e0a06d commit 75c77df Copy full SHA for 75c77df
File tree 1 file changed +13
-8
lines changed
1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change 1
1
package model
2
2
3
3
import (
4
- "math/rand"
4
+ "crypto/rand"
5
+ "encoding/base64"
5
6
)
6
7
7
- var letterRunes = []rune ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" )
8
-
9
- func RandStringRunes (n int ) string {
10
- b := make ([]rune , n )
11
- for i := range b {
12
- b [i ] = letterRunes [rand .Intn (len (letterRunes ))]
8
+ func generateRandomBytes (n int ) []byte {
9
+ b := make ([]byte , n )
10
+ _ , err := rand .Read (b )
11
+ if err != nil {
12
+ panic (err )
13
13
}
14
- return string (b )
14
+ return b
15
+ }
16
+
17
+ func RandStringRunes (s int ) string {
18
+ b := generateRandomBytes (s )
19
+ return base64 .URLEncoding .EncodeToString (b )
15
20
}
16
21
17
22
func MergeAnnotations (requested map [string ]string , existing map [string ]string ) map [string ]string {
You can’t perform that action at this time.
0 commit comments