commit e0a4e1251f7714984c0dc33b3fe20ce738283bb0 Author: Ricardo Date: Thu Jun 25 18:55:56 2020 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f4d432a --- /dev/null +++ b/.gitignore @@ -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/ + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9c31dda --- /dev/null +++ b/LICENSE @@ -0,0 +1,14 @@ +DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + +Version 2, December 2004 + +Copyright (C) 2004 Sam Hocevar + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..7c60000 --- /dev/null +++ b/README.md @@ -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) +``` diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..5fd8fe6 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.dymstro.nl/Dymstro/go-randomstring + +go 1.14 diff --git a/main.go b/main.go new file mode 100644 index 0000000..5060362 --- /dev/null +++ b/main.go @@ -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) +}