3
0

Bump github.com/Masterminds/goutils from 1.1.0 to 1.1.1 in /server

Bumps [github.com/Masterminds/goutils](https://github.com/Masterminds/goutils) from 1.1.0 to 1.1.1.
- [Release notes](https://github.com/Masterminds/goutils/releases)
- [Changelog](https://github.com/Masterminds/goutils/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Masterminds/goutils/compare/v1.1.0...v1.1.1)

---
updated-dependencies:
- dependency-name: github.com/Masterminds/goutils
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot]
2023-04-07 15:08:52 +00:00
committed by Jože Fortun
parent 1d0fa8a545
commit 7c19b2c0b9
6 changed files with 25 additions and 50 deletions
+2 -23
View File
@@ -21,7 +21,6 @@ import (
"fmt"
"math"
"math/big"
"regexp"
"unicode"
)
@@ -99,27 +98,7 @@ Returns:
error - an error stemming from an invalid parameter within underlying function, CryptoRandom(...)
*/
func CryptoRandomAlphaNumeric(count int) (string, error) {
if count == 0 {
return "", nil
}
RandomString, err := CryptoRandom(count, 0, 0, true, true)
if err != nil {
return "", fmt.Errorf("Error: %s", err)
}
match, err := regexp.MatchString("([0-9]+)", RandomString)
if err != nil {
panic(err)
}
if !match {
//Get the position between 0 and the length of the string-1 to insert a random number
position := getCryptoRandomInt(count)
//Insert a random number between [0-9] in the position
RandomString = RandomString[:position] + string('0' + getCryptoRandomInt(10)) + RandomString[position + 1:]
return RandomString, err
}
return RandomString, err
return CryptoRandom(count, 0, 0, true, true)
}
/*
@@ -204,7 +183,7 @@ func CryptoRandom(count int, start int, end int, letters bool, numbers bool, cha
if chars == nil {
ch = rune(getCryptoRandomInt(gap) + int64(start))
} else {
ch = chars[getCryptoRandomInt(gap) + int64(start)]
ch = chars[getCryptoRandomInt(gap)+int64(start)]
}
if letters && unicode.IsLetter(ch) || numbers && unicode.IsDigit(ch) || !letters && !numbers {
+2 -22
View File
@@ -20,7 +20,6 @@ import (
"fmt"
"math"
"math/rand"
"regexp"
"time"
"unicode"
)
@@ -75,12 +74,10 @@ func RandomNumeric(count int) (string, error) {
/*
RandomAlphabetic creates a random string whose length is the number of characters specified.
Characters will be chosen from the set of alpha-numeric characters as indicated by the arguments.
Characters will be chosen from the set of alphabetic characters.
Parameters:
count - the length of random string to create
letters - if true, generated string may include alphabetic characters
numbers - if true, generated string may include numeric characters
Returns:
string - the random string
@@ -102,24 +99,7 @@ Returns:
error - an error stemming from an invalid parameter within underlying function, RandomSeed(...)
*/
func RandomAlphaNumeric(count int) (string, error) {
RandomString, err := Random(count, 0, 0, true, true)
if err != nil {
return "", fmt.Errorf("Error: %s", err)
}
match, err := regexp.MatchString("([0-9]+)", RandomString)
if err != nil {
panic(err)
}
if !match {
//Get the position between 0 and the length of the string-1 to insert a random number
position := rand.Intn(count)
//Insert a random number between [0-9] in the position
RandomString = RandomString[:position] + string('0'+rand.Intn(10)) + RandomString[position+1:]
return RandomString, err
}
return RandomString, err
return Random(count, 0, 0, true, true)
}
/*
+16
View File
@@ -222,3 +222,19 @@ func IndexOf(str string, sub string, start int) int {
func IsEmpty(str string) bool {
return len(str) == 0
}
// Returns either the passed in string, or if the string is empty, the value of defaultStr.
func DefaultString(str string, defaultStr string) string {
if IsEmpty(str) {
return defaultStr
}
return str
}
// Returns either the passed in string, or if the string is whitespace, empty (""), the value of defaultStr.
func DefaultIfBlank(str string, defaultStr string) string {
if IsBlank(str) {
return defaultStr
}
return str
}