Skip to content

Instantly share code, notes, and snippets.

@x893675
Created October 26, 2020 07:29
Show Gist options
  • Save x893675/f4ad82a0c59b686b31e19729731b675d to your computer and use it in GitHub Desktop.
Save x893675/f4ad82a0c59b686b31e19729731b675d to your computer and use it in GitHub Desktop.
generate access token
package main
import (
"crypto/rand"
"fmt"
"math/big"
)
const (
characters = "bcdfghjklmnpqrstvwxz2456789"
tokenLength = 54
)
var charsLength = big.NewInt(int64(len(characters)))
func Generate() (string, error) {
token := make([]byte, tokenLength)
for i := range token {
r, err := rand.Int(rand.Reader, charsLength)
if err != nil {
return "", err
}
token[i] = characters[r.Int64()]
}
return string(token), nil
}
func main() {
//rand.Seed(time.Now().UnixNano())
s, err := Generate()
if err != nil {
panic(err)
}
fmt.Println(s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment