20 lines
421 B
Go
20 lines
421 B
Go
package ids
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
"fmt"
|
|
)
|
|
|
|
// ID is a transport-neutral opaque identifier primitive. Domain packages wrap it
|
|
// in strong semantic ID types; do not pass bare ID across semantic boundaries.
|
|
type ID string
|
|
|
|
func New() (ID, error) {
|
|
var b [16]byte
|
|
if _, err := rand.Read(b[:]); err != nil {
|
|
return "", fmt.Errorf("generate id: %w", err)
|
|
}
|
|
return ID(hex.EncodeToString(b[:])), nil
|
|
}
|