summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/labstack/gommon
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/labstack/gommon')
-rw-r--r--vendor/github.com/labstack/gommon/random/random.go40
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...)
}