feat: Add ID generation utilities with rule ID, event ID, and random string generators

- Add GenerateRuleID function using nanosecond timestamp
- Add GetCurrentTime helper returning current time
- Add GenerateEventID function with "evt_" prefix and 16-character random string
- Add GenerateRandomString function with alphanumeric charset
This commit is contained in:
nutcas3
2026-05-02 05:09:20 +03:00
parent b160029e30
commit cac6db74a7
@@ -0,0 +1,31 @@
package id
import (
"fmt"
"time"
)
func GenerateRuleID() string {
return fmt.Sprintf("rule_%d", GetCurrentTime().UnixNano())
}
// GetCurrentTime returns the current time
func GetCurrentTime() time.Time {
return time.Now()
}
func GenerateEventID() string {
// Generate unique event ID (implementation depends on your ID generation strategy)
return "evt_" + GenerateRandomString(16)
}
func GenerateRandomString(length int) string {
// Generate random string (implementation depends on your random string generation)
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
b := make([]byte, length)
for i := range b {
b[i] = charset[i%len(charset)]
}
return string(b)
}