Initial commit
This commit is contained in:
commit
e0a4e1251f
5 changed files with 81 additions and 0 deletions
17
.gitignore
vendored
Normal file
17
.gitignore
vendored
Normal 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
14
LICENSE
Normal 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
16
README.md
Normal 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
3
go.mod
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
module git.dymstro.nl/Dymstro/go-randomstring
|
||||||
|
|
||||||
|
go 1.14
|
31
main.go
Normal file
31
main.go
Normal 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)
|
||||||
|
}
|
Loading…
Reference in a new issue