API key generator, using YAML format instead of hand rolled parser
This commit is contained in:
+10
-3
@@ -1,12 +1,19 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"crypto/rand"
|
||||
"io"
|
||||
|
||||
"github.com/lytics/base62"
|
||||
)
|
||||
|
||||
func RandomSecret() string {
|
||||
// 256 bit secret
|
||||
buf := make([]byte, 32)
|
||||
_, err := io.ReadFull(rand.Reader, buf)
|
||||
// cannot error
|
||||
bin, _ := uuid.New().MarshalBinary()
|
||||
return base62.StdEncoding.EncodeToString(bin)
|
||||
if err != nil {
|
||||
panic("could not read random")
|
||||
}
|
||||
return base62.StdEncoding.EncodeToString(buf)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user