2023-11-01 00:05:17 +00:00
|
|
|
package aid
|
|
|
|
|
|
|
|
import (
|
2023-12-19 16:47:13 +00:00
|
|
|
m "math/rand"
|
2023-11-01 00:05:17 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
2024-02-11 00:27:08 +00:00
|
|
|
"regexp"
|
2023-12-13 22:52:16 +00:00
|
|
|
"strconv"
|
2023-11-01 00:05:17 +00:00
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
func WaitForExit() {
|
|
|
|
sc := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
|
|
|
<-sc
|
2023-11-05 01:58:00 +00:00
|
|
|
}
|
|
|
|
|
2023-12-11 00:06:41 +00:00
|
|
|
func RandomString(n int) string {
|
2023-12-13 22:52:16 +00:00
|
|
|
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
|
|
|
|
|
|
|
s := make([]rune, n)
|
|
|
|
for i := range s {
|
2023-12-19 16:47:13 +00:00
|
|
|
s[i] = letters[m.Intn(len(letters))]
|
2023-12-13 22:52:16 +00:00
|
|
|
}
|
|
|
|
return string(s)
|
|
|
|
}
|
|
|
|
|
2024-02-11 00:27:08 +00:00
|
|
|
func RandomInt(min, max int) int {
|
|
|
|
return m.Intn(max - min) + min
|
|
|
|
}
|
|
|
|
|
2023-12-13 22:52:16 +00:00
|
|
|
func FormatNumber(number int) string {
|
|
|
|
str := ""
|
|
|
|
for i, char := range ReverseString(strconv.Itoa(number)) {
|
|
|
|
if i % 3 == 0 && i != 0 {
|
|
|
|
str += ","
|
|
|
|
}
|
|
|
|
str += string(char)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ReverseString(str)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ReverseString(input string) string {
|
|
|
|
str := ""
|
|
|
|
for _, char := range input {
|
|
|
|
str = string(char) + str
|
|
|
|
}
|
|
|
|
return str
|
2024-02-10 00:34:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ToHex(number int) string {
|
|
|
|
inta := strconv.FormatInt(int64(number), 16)
|
|
|
|
|
|
|
|
if len(inta) == 1 {
|
|
|
|
return "0" + inta
|
|
|
|
}
|
|
|
|
|
|
|
|
return inta
|
2024-02-11 00:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Regex(str, regex string) *string {
|
|
|
|
// reg := regexp.MustCompile(`(?:CID_)(\d+|A_\d+)(?:_.+)`).FindStringSubmatch(strings.Join(split[:], "_"))
|
|
|
|
reg := regexp.MustCompile(regex).FindStringSubmatch(str)
|
|
|
|
if len(reg) > 1 {
|
|
|
|
return ®[1]
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2023-11-01 00:05:17 +00:00
|
|
|
}
|