Add first version of gemini-grc.

This commit is contained in:
2024-12-27 12:09:55 +02:00
parent 93822b239e
commit b52df073e9
30 changed files with 2754 additions and 0 deletions

36
util/util.go Normal file
View File

@@ -0,0 +1,36 @@
package util
import (
"crypto/rand"
"encoding/json"
"fmt"
"math/big"
"runtime/debug"
)
func PrintStackAndPanic(err error) {
fmt.Printf("Error %s Stack trace:\n%s", err, debug.Stack())
panic("PANIC")
}
// SecureRandomInt returns a cryptographically secure random integer in the range [0,max).
// Panics if max <= 0 or if there's an error reading from the system's secure
// random number generator.
func SecureRandomInt(max int) int {
// Convert max to *big.Int for crypto/rand operations
maxBig := big.NewInt(int64(max))
// Generate random number
n, err := rand.Int(rand.Reader, maxBig)
if err != nil {
PrintStackAndPanic(fmt.Errorf("could not generate a random integer between 0 and %d", max))
}
// Convert back to int
return int(n.Int64())
}
func PrettyJson(data string) string {
marshalled, _ := json.MarshalIndent(data, "", " ")
return fmt.Sprintf("%s\n", marshalled)
}