https://github.com/sillyhatxu/id-generator
https://github.com/sillyhatxu/id-generator
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/sillyhatxu/id-generator
- Owner: sillyhatxu
- Created: 2019-09-21T04:59:45.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-15T08:04:47.000Z (over 5 years ago)
- Last Synced: 2025-01-31T07:45:34.302Z (4 months ago)
- Language: Go
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# id-generator
## [example](https://github.com/sillyhatxu/id-generator/blob/master/generator_test.go)
## Initialize your project
```
go mod init github.com/sillyhatxu/id-generator
```## Updating dependencies
```
go mod vendor
```## verify dependencies
```
go mod verify
```## remove dependencies that is not used
```
go mod tidy
```## print dependence diagram
```
go mod graph
```## download dependencies
```
go mod download
```# Release Template
### Feature
* [NEW] Support for Go Modules [#17](https://github.com/sillyhatxu/convenient-utils/issues/17)
---
### Bug fix
* [FIX] Truncate Latency precision in long running request [#17](https://github.com/sillyhatxu/convenient-utils/issues/17)
## new client
```
client := NewGeneratorClient("test")
id, err := client.GeneratorGroupId("test-group")
```## params
```
client := NewGeneratorClient(
"test",
Prefix("GT"),
GroupLength(3),
SequenceFormat("%02d"),
Instance("8"),
LifeCycle(5*time.Second),
)
id, err := client.GeneratorId()
```## example
```
func TestGeneratorClient_GeneratorId(t *testing.T) {
client :=.NewGeneratorClient("test")
for i := 0; i < 100; i++ {
id, err := client.GeneratorId()
assert.Nil(t, err)
fmt.Println(id)
}
}
```> output
```
15690628250001
15690628250002
15690628250003
15690628250004
15690628250005
15690628250006
15690628250007
15690628250008
15690628250009
15690628250010
``````
func TestGeneratorClient_GeneratorGroupId(t *testing.T) {
client := NewGeneratorClient("test", Prefix("GT"), GroupLength(3), SequenceFormat("%02d"))
for i := 0; i < 100; i++ {
id, err := client.GeneratorGroupId("group")
assert.Nil(t, err)
fmt.Println(id)
}
}
```> output
```
GT156906285601516
GT156906285602516
GT156906285603516
GT156906285604516
GT156906285605516
GT156906285606516
GT156906285607516
GT156906285608516
```> Instance : used to prevent ID duplication when multiple instances generate ids
```
func TestGeneratorClient_GeneratorGroupIdInstance(t *testing.T) {
client := NewGeneratorClient("test", Prefix("GT"), GroupLength(3), SequenceFormat("%02d"), Instance("8"))
for i := 0; i < 100; i++ {
id, err := client.GeneratorGroupId("group")
assert.Nil(t, err)
fmt.Println(id)
}
}
```> output
```
GT8156906575501516
GT8156906575502516
GT8156906575503516
GT8156906575504516
GT8156906575505516
GT8156906575506516
```