snow/aid/aid.go
2024-01-21 17:49:14 +00:00

45 lines
774 B
Go

package aid
import (
m "math/rand"
"os"
"os/signal"
"strconv"
"syscall"
)
func WaitForExit() {
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc
}
func RandomString(n int) string {
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
s := make([]rune, n)
for i := range s {
s[i] = letters[m.Intn(len(letters))]
}
return string(s)
}
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
}