From e6aed353a2b288caa6c6a632a80d5484e4614b2c Mon Sep 17 00:00:00 2001 From: huker667 Date: Wed, 25 Mar 2026 14:48:48 +0300 Subject: move RandStr to helpers --- helpers/helpers.go | 12 ++++++++++++ package/package.go | 11 +---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/helpers/helpers.go b/helpers/helpers.go index ac92e6a..1db691b 100644 --- a/helpers/helpers.go +++ b/helpers/helpers.go @@ -3,9 +3,13 @@ package helpers import ( "fmt" "strings" + "math/rand" + "time" "strconv" ) +var r = rand.New(rand.NewSource(time.Now().UnixNano())) + func Ask(str string) bool { var input string fmt.Printf("-> %s (Y/n): ", str) @@ -30,3 +34,11 @@ func ToString(v interface{}) string { return "" } } + +func RandStr(n int) string { + b := make([]byte, n) + for i := range b { + b[i] = byte(r.Intn(26) + 'a') + } + return string(b) +} diff --git a/package/package.go b/package/package.go index 6372688..2afd854 100644 --- a/package/package.go +++ b/package/package.go @@ -3,7 +3,6 @@ package pkg import ( "fmt" "bufio" - "math/rand" "slices" "strings" "errors" @@ -27,16 +26,8 @@ type Package struct { Data []interface{} } -func randStr(n int) string { - b := make([]byte, n) - for i := range b { - b[i] = byte(rand.Intn(26) + 'a') - } - return string(b) -} - func randomTempDir(destDir string) string { - tempDir := "qulay_" + randStr(10) + tempDir := "qulay_" + helpers.RandStr(10) tempDirPath := filepath.Join(destDir, tempDir) os.MkdirAll(tempDirPath, 0755) return tempDirPath -- cgit v1.3.1