21 lines
328 B
Go
21 lines
328 B
Go
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()
|
|
}
|