mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-16 00:45:13 +00:00
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:
@@ -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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user