convert token to library

This commit is contained in:
wish
2022-11-07 00:22:16 +11:00
parent c9955a724f
commit 181ea56837
2 changed files with 17 additions and 12 deletions

13
common/token/token.go Normal file
View File

@@ -0,0 +1,13 @@
package token
import "math/rand"
// Generate returns an alphanumeric token of specified length
func Generate(length int) string {
var chars = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
b := make([]rune, length)
for i := range b {
b[i] = chars[rand.Intn(len(chars))]
}
return string(b)
}