API key generator, using YAML format instead of hand rolled parser

This commit is contained in:
David Zhao
2020-12-27 00:01:19 -08:00
parent c489ca570b
commit 353f35443a
7 changed files with 105 additions and 27 deletions
+10 -3
View File
@@ -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)
}