2023-11-01 00:05:17 +00:00
|
|
|
package aid
|
|
|
|
|
|
|
|
import (
|
2023-12-11 00:06:41 +00:00
|
|
|
"math/rand"
|
2023-11-01 00:05:17 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2023-11-09 18:53:19 +00:00
|
|
|
|
|
|
|
"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
|
2023-11-05 01:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
|
|
|
|
|
|
|
s := make([]rune, n)
|
|
|
|
for i := range s {
|
|
|
|
s[i] = letters[rand.Intn(len(letters))]
|
|
|
|
}
|
|
|
|
return string(s)
|
2023-11-01 00:05:17 +00:00
|
|
|
}
|