This commit is contained in:
laodaming
2023-06-27 14:25:25 +08:00
parent 116171dddd
commit c5bcf9d676
15 changed files with 536 additions and 5 deletions

View File

@@ -0,0 +1,16 @@
package snow_id_generator
import (
"fmt"
"github.com/bwmarrin/snowflake"
"time"
)
// 雪花算法生成id
func GenSnowId() (string, error) {
node, err := snowflake.NewNode(1)
if err != nil {
return "", err
}
return fmt.Sprintf("%s%s", time.Now().Format("20060102"), node.Generate().Base58()), nil
}