forked from mozilla/mig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc.go
27 lines (23 loc) · 887 Bytes
/
misc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Contributor: Aaron Meihm [email protected] [:alm]
package mig /* import "github.com/mozilla/mig" */
// Misc support functions used in various places within MIG
import (
mrand "math/rand"
"time"
)
// RandAPIKeyString is used for prefix and key generation, and just
// returns a random string consisting of alphanumeric characters of
// length characters long
func RandAPIKeyString(length int) string {
ret := make([]byte, length)
lset := []byte("abcdefghijklmnopqrstuvwxyzABCDEFCHIJKLMNOPQRSTUVWXYZ0123456789")
r := mrand.New(mrand.NewSource(time.Now().UnixNano()))
for i := 0; i < len(ret); i++ {
ret[i] = lset[r.Int()%len(lset)]
}
return string(ret[:len(ret)])
}