正在显示
1 个修改的文件
包含
9 行增加
和
2 行删除
| @@ -39,13 +39,20 @@ func AssertJson(object interface{})string{ | @@ -39,13 +39,20 @@ func AssertJson(object interface{})string{ | ||
| 39 | 39 | ||
| 40 | var randomChars = "ABCDEFGHJKMNPQRSTWXYZabcdefhjkmnprstwxyz2345678" /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/ | 40 | var randomChars = "ABCDEFGHJKMNPQRSTWXYZabcdefhjkmnprstwxyz2345678" /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/ |
| 41 | func RandomString(l int)string{ | 41 | func RandomString(l int)string{ |
| 42 | + return RandomStringWithChars(l,randomChars) | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +func RandomStringWithChars(l int,chars string)string{ | ||
| 42 | if l<=0{ | 46 | if l<=0{ |
| 43 | return "" | 47 | return "" |
| 44 | } | 48 | } |
| 45 | - lenChars :=len(randomChars) -1 | 49 | + if len(chars)==0{ |
| 50 | + return "" | ||
| 51 | + } | ||
| 52 | + lenChars :=len(chars) -1 | ||
| 46 | rsp :=bytes.NewBuffer(nil) | 53 | rsp :=bytes.NewBuffer(nil) |
| 47 | for i:=0;i<l;i++{ | 54 | for i:=0;i<l;i++{ |
| 48 | - rsp.WriteByte(randomChars[rand.Intn(lenChars)]) | 55 | + rsp.WriteByte(chars[rand.Intn(lenChars)]) |
| 49 | } | 56 | } |
| 50 | return rsp.String() | 57 | return rsp.String() |
| 51 | } | 58 | } |
-
请 注册 或 登录 后发表评论