Initial commit

This commit is contained in:
Ricardo 2020-06-25 18:55:56 +02:00
commit e0a4e1251f
Signed by: Dymstro
GPG key ID: A90945AF5D94F15D
5 changed files with 81 additions and 0 deletions

17
.gitignore vendored Normal file
View file

@ -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/

14
LICENSE Normal file
View file

@ -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.

16
README.md Normal file
View file

@ -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)
```

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module git.dymstro.nl/Dymstro/go-randomstring
go 1.14

31
main.go Normal file
View file

@ -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)
}