mirror of
https://github.com/appleboy/drone-scp.git
synced 2026-06-26 15:52:13 +08:00
9787fcfb60
* refactor: add vendor folder. Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
40 lines
842 B
Go
40 lines
842 B
Go
package random
|
|
|
|
import (
|
|
"math/rand"
|
|
"time"
|
|
)
|
|
|
|
type (
|
|
// Charset is string type
|
|
Charset string
|
|
)
|
|
|
|
const (
|
|
// Alphanumeric contain Alphabetic and Numeric
|
|
Alphanumeric Charset = Alphabetic + Numeric
|
|
// Alphabetic is \w+ \W
|
|
Alphabetic Charset = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
// Numeric is number list
|
|
Numeric Charset = "0123456789"
|
|
// Hex is Hexadecimal
|
|
Hex Charset = Numeric + "abcdef"
|
|
)
|
|
|
|
var seededRand = rand.New(
|
|
rand.NewSource(time.Now().UnixNano()))
|
|
|
|
// StringWithCharset support rand string you defined
|
|
func StringWithCharset(length int, charset Charset) string {
|
|
b := make([]byte, length)
|
|
for i := range b {
|
|
b[i] = charset[seededRand.Intn(len(charset))]
|
|
}
|
|
return string(b)
|
|
}
|
|
|
|
// String supply rand string
|
|
func String(length int) string {
|
|
return StringWithCharset(length, Alphanumeric)
|
|
}
|