Created
October 26, 2020 07:29
-
-
Save x893675/f4ad82a0c59b686b31e19729731b675d to your computer and use it in GitHub Desktop.
generate access token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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