feat: add entity and swagger
This commit is contained in:
1 parent
0416c356b8
commit
346742b157
12 files changed
+652
-66
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import SnowflakeID from 'snowflake-id';
|
||||
|
||||
export class SnowflakeUtil {
|
||||
private static instance: SnowflakeID;
|
||||
|
||||
static initialize(workerId: number = 1, datacenterId: number = 1): void {
|
||||
this.instance = new SnowflakeID({
|
||||
workerId, // 机器 ID
|
||||
datacenterId, // 数据中心 ID
|
||||
});
|
||||
}
|
||||
|
||||
static generateId(): string {
|
||||
if (!this.instance) {
|
||||
throw new Error('SnowflakeUtil is not initialized.');
|
||||
}
|
||||
return this.instance.generate().toString();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user