diff options
author | Wim <wim@42.be> | 2017-06-06 00:01:05 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2017-06-06 00:04:18 +0200 |
commit | 3a183cb218c6812964a70d2e75884ad7071d9c0c (patch) | |
tree | ee0d2492c27e84ace88acfcfdc533545f42ccb21 /vendor/github.com/labstack/gommon/random | |
parent | 2eecaccd1c77e8990a80e6b4b6ad6b13a9c95896 (diff) | |
download | matterbridge-msglm-3a183cb218c6812964a70d2e75884ad7071d9c0c.tar.gz matterbridge-msglm-3a183cb218c6812964a70d2e75884ad7071d9c0c.tar.bz2 matterbridge-msglm-3a183cb218c6812964a70d2e75884ad7071d9c0c.zip |
Update vendor
Diffstat (limited to 'vendor/github.com/labstack/gommon/random')
-rw-r--r-- | vendor/github.com/labstack/gommon/random/random.go | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/vendor/github.com/labstack/gommon/random/random.go b/vendor/github.com/labstack/gommon/random/random.go index b76bd9b3..b1ae864a 100644 --- a/vendor/github.com/labstack/gommon/random/random.go +++ b/vendor/github.com/labstack/gommon/random/random.go @@ -2,22 +2,24 @@ package random import ( "math/rand" + "strings" "time" ) type ( Random struct { - charset Charset } - - Charset string ) +// Charsets const ( - Alphanumeric Charset = Alphabetic + Numeric - Alphabetic Charset = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - Numeric Charset = "0123456789" - Hex Charset = Numeric + "abcdef" + Uppercase string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + Lowercase = "abcdefghijklmnopqrstuvwxyz" + Alphabetic = Uppercase + Lowercase + Numeric = "0123456789" + Alphanumeric = Alphabetic + Numeric + Symbols = "`" + `~!@#$%^&*()-_+={}[]|\;:"<>,./?` + Hex = Numeric + "abcdef" ) var ( @@ -26,27 +28,21 @@ var ( func New() *Random { rand.Seed(time.Now().UnixNano()) - return &Random{ - charset: Alphanumeric, - } -} - -func (r *Random) SetCharset(c Charset) { - r.charset = c + return new(Random) } -func (r *Random) String(length uint8) string { +func (r *Random) String(length uint8, charsets ...string) string { + charset := strings.Join(charsets, "") + if charset == "" { + charset = Alphanumeric + } b := make([]byte, length) for i := range b { - b[i] = r.charset[rand.Int63()%int64(len(r.charset))] + b[i] = charset[rand.Int63()%int64(len(charset))] } return string(b) } -func SetCharset(c Charset) { - global.SetCharset(c) -} - -func String(length uint8) string { - return global.String(length) +func String(length uint8, charsets ...string) string { + return global.String(length, charsets...) } |