snow/aid/aid.go

58 lines
1.0 KiB
Go
Raw Normal View History

2023-11-01 00:05:17 +00:00
package aid
import (
m "math/rand"
2023-11-01 00:05:17 +00:00
"os"
"os/signal"
2023-12-13 22:52:16 +00:00
"strconv"
2023-11-01 00:05:17 +00:00
"syscall"
"github.com/goccy/go-json"
2023-11-01 00:05:17 +00:00
)
func WaitForExit() {
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc
}
func JSONStringify(input interface{}) string {
json, _ := json.Marshal(input)
return string(json)
}
func JSONParse(input string) interface{} {
var output interface{}
json.Unmarshal([]byte(input), &output)
return output
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 {
s[i] = letters[m.Intn(len(letters))]
2023-12-13 22:52:16 +00:00
}
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
2023-11-01 00:05:17 +00:00
}