forked from bepass-org/bepass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
35 lines (30 loc) · 749 Bytes
/
utils.go
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
// Package utils provides utility functions for the application.
package utils
import (
"crypto/rand"
"io"
)
var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-"
// ShortID generates a random short ID of the specified length.
func ShortID(length int) string {
ll := len(chars)
b := make([]byte, length)
rand.Read(b) // generates len(b) random bytes
for i := 0; i < length; i++ {
b[i] = chars[int(b[i])%ll]
}
return string(b)
}
type BufferedReader struct {
FirstPacketData []byte
BufReader io.Reader
FirstTime bool
}
func (r *BufferedReader) Read(p []byte) (int, error) {
if r.FirstTime {
r.FirstTime = false
n := copy(p, r.FirstPacketData)
return n, nil
}
return r.BufReader.Read(p)
}