first commit
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
package orm
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"github.com/sixafter/nanoid"
|
||||
)
|
||||
|
||||
func GenID() string {
|
||||
id, err := nanoid.New()
|
||||
if err != nil {
|
||||
// Fallback to random hex
|
||||
b := make([]byte, 16)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
return "fallback-id"
|
||||
}
|
||||
return hex.EncodeToString(b)
|
||||
}
|
||||
return id.String()
|
||||
}
|
||||
Reference in New Issue
Block a user