move RandStr to helpers
This commit is contained in:
1 parent
4ff821beed
commit
e6aed353a2
2 files changed
+13
-10
No files matched your search
@@ -3,9 +3,13 @@ package helpers
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var r = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
|
|
||||||
func Ask(str string) bool {
|
func Ask(str string) bool {
|
||||||
var input string
|
var input string
|
||||||
fmt.Printf("-> %s (Y/n): ", str)
|
fmt.Printf("-> %s (Y/n): ", str)
|
||||||
@@ -30,3 +34,11 @@ func ToString(v interface{}) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RandStr(n int) string {
|
||||||
|
b := make([]byte, n)
|
||||||
|
for i := range b {
|
||||||
|
b[i] = byte(r.Intn(26) + 'a')
|
||||||
|
}
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
+1
-10
@@ -3,7 +3,6 @@ package pkg
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"bufio"
|
"bufio"
|
||||||
"math/rand"
|
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"errors"
|
"errors"
|
||||||
@@ -27,16 +26,8 @@ type Package struct {
|
|||||||
Data []interface{}
|
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 {
|
func randomTempDir(destDir string) string {
|
||||||
tempDir := "qulay_" + randStr(10)
|
tempDir := "qulay_" + helpers.RandStr(10)
|
||||||
tempDirPath := filepath.Join(destDir, tempDir)
|
tempDirPath := filepath.Join(destDir, tempDir)
|
||||||
os.MkdirAll(tempDirPath, 0755)
|
os.MkdirAll(tempDirPath, 0755)
|
||||||
return tempDirPath
|
return tempDirPath
|
||||||
|
|||||||
Reference in new issue
Block a user