Library for generating/validating unique UIDs within a cluster
go get -u github.com/Bookshelf-Writer/PointerFactory
- Binding occurs to the date, the reference point is set during initialization
- The allowed number of parallel nodes to maintain uniqueness within the group is 65535
- Within a group, you can receive up to 4294967295 unique pointers per minute
- Multi-stage validation, returning an error at the first occurrence
- There is a checksum (consists of two characters to avoid collisions)
- The maximum allowable size of the number system is 36. The minimum is 2.
The maximum length of the generated string does not exceed 20 characters
userGroup := 'u'
regGroup := 'r'
commentGroup := 'g'
groups := []rune{userGroup, regGroup, commentGroup}
startTime := time.Date(2024, 1, 1, 1, 1, 0, 0, time.UTC)
uid, err := New(groups, 0, 36, startTime) //Initialize the factory
if err != nil {
panic(err)
}
newUserID, _ := uid.New(userGroup)
newRegID, _ := uid.New(regGroup)
newCommentID, _ := uid.New(commentGroup)
fmt.Println(newUserID, newRegID) //Outputs: u09vnb0l9 r09vnb0i6
fmt.Println(uid.IsValid(newCommentID)) //Returns nil since the pointer is valid
uid.Close()