-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutil.go
More file actions
40 lines (32 loc) · 691 Bytes
/
Copy pathutil.go
File metadata and controls
40 lines (32 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"crypto/rand"
"io"
"log/slog"
"math/big"
)
func LogClose(closer io.Closer) {
if errClose := closer.Close(); errClose != nil {
slog.Error("Error trying to close", errAttr(errClose))
}
}
func IgnoreClose(closer io.Closer) {
_ = closer.Close()
}
func RandomString(n int) string {
var (
letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
outBytes = make([]rune, n)
)
for i := range outBytes {
outBytes[i] = letters[RandInt(len(letters))]
}
return string(outBytes)
}
func RandInt(i int) int {
value, errInt := rand.Int(rand.Reader, big.NewInt(int64(i)))
if errInt != nil {
panic(errInt)
}
return int(value.Int64())
}