We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 053008f commit 93dc7a3Copy full SHA for 93dc7a3
util/token/token.go
@@ -3,15 +3,13 @@ package token
3
import (
4
"crypto/rand"
5
"encoding/base32"
6
- "encoding/base64"
+ "strings"
7
)
8
9
+var encoder = base32.NewEncoding("0123456789abcdefghjkmnpqrstvwxyz")
10
+
11
func New64() string {
- b, err := RandN(8)
- if err != nil {
12
- panic(err)
13
- }
14
- return base64.StdEncoding.EncodeToString(b)
+ return New(8)
15
}
16
17
func RandN(n int) ([]byte, error) {
@@ -24,9 +22,13 @@ func RandN(n int) ([]byte, error) {
24
22
25
23
26
func New32() string {
27
- b, err := RandN(5)
+ return New(5)
+}
28
+func New(n int) string {
29
+ b, err := RandN(n)
30
if err != nil {
31
panic(err)
32
- return base32.StdEncoding.EncodeToString(b)
33
+ return strings.TrimRight(encoder.EncodeToString(b), "=")
34
0 commit comments