Explorar el Código

Exposed method to set charset

Signed-off-by: Vishal Rana <vr@labstack.com>
Vishal Rana hace 9 años
padre
commit
445cf40e6d
Se han modificado 2 ficheros con 11 adiciones y 0 borrados
  1. 8 0
      random/random.go
  2. 3 0
      random/random_test.go

+ 8 - 0
random/random.go

@@ -31,6 +31,10 @@ func New() *Random {
 	}
 }
 
+func (r *Random) SetCharset(c Charset) {
+	r.charset = c
+}
+
 func (r *Random) String(length uint8) string {
 	b := make([]byte, length)
 	for i := range b {
@@ -39,6 +43,10 @@ func (r *Random) String(length uint8) string {
 	return string(b)
 }
 
+func SetCharset(c Charset) {
+	global.SetCharset(c)
+}
+
 func String(length uint8) string {
 	return global.String(length)
 }

+ 3 - 0
random/random_test.go

@@ -8,4 +8,7 @@ import (
 
 func Test(t *testing.T) {
 	assert.Len(t, String(32), 32)
+	r := New()
+	r.SetCharset(Numeric)
+	assert.Len(t, r.String(8), 8)
 }