commit
e0a4e1251f
5 changed files with 81 additions and 0 deletions
@ -0,0 +1,17 @@
|
||||
# ---> Go |
||||
# Binaries for programs and plugins |
||||
*.exe |
||||
*.exe~ |
||||
*.dll |
||||
*.so |
||||
*.dylib |
||||
|
||||
# Test binary, built with `go test -c` |
||||
*.test |
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE |
||||
*.out |
||||
|
||||
# Dependency directories (remove the comment below to include it) |
||||
# vendor/ |
||||
|
@ -0,0 +1,14 @@
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |
||||
|
||||
Version 2, December 2004 |
||||
|
||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> |
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified copies of |
||||
this license document, and changing it is allowed as long as the name is changed. |
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |
||||
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO. |
@ -0,0 +1,16 @@
|
||||
# go-randomstring |
||||
|
||||
Simple go module for generating random strings |
||||
|
||||
## Usage |
||||
|
||||
|
||||
``` |
||||
import ( |
||||
''' |
||||
"git.dymstro.nl/Dymstro/go-randomstring" |
||||
''' |
||||
) |
||||
|
||||
randomstring.Gen(length int, lower bool, upper bool, num bool) |
||||
``` |
@ -0,0 +1,31 @@
|
||||
package randomstring |
||||
|
||||
import ( |
||||
"math/rand" |
||||
"time" |
||||
) |
||||
|
||||
func init() { |
||||
rand.Seed(time.Now().UnixNano()) |
||||
} |
||||
|
||||
func Gen(length int, lower bool, upper bool, num bool) string { |
||||
r := [3]string{"abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "1234567890",} |
||||
|
||||
chars := []rune("") |
||||
if lower { |
||||
chars = []rune(string(chars) + r[0]) |
||||
} |
||||
if upper { |
||||
chars = []rune(string(chars) + r[1]) |
||||
} |
||||
if num { |
||||
chars = []rune(string(chars) + r[2]) |
||||
} |
||||
|
||||
str := make([]rune, length) |
||||
for i := range str { |
||||
str[i] = chars[rand.Intn(len(chars))] |
||||
} |
||||
return string(str) |
||||
} |
Loading…
Reference in new issue