Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/younglifestyle/goLeaf
golang leaf,REF. Meituan-Dianping Leaf,ID发号器
https://github.com/younglifestyle/goLeaf
go-kratos golang kratos leaf
Last synced: 5 days ago
JSON representation
golang leaf,REF. Meituan-Dianping Leaf,ID发号器
- Host: GitHub
- URL: https://github.com/younglifestyle/goLeaf
- Owner: younglifestyle
- License: apache-2.0
- Created: 2022-04-12T10:35:46.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-28T14:15:49.000Z (7 months ago)
- Last Synced: 2024-08-02T18:36:32.435Z (3 months ago)
- Topics: go-kratos, golang, kratos, leaf
- Language: Go
- Homepage:
- Size: 394 KB
- Stars: 80
- Watchers: 9
- Forks: 14
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Leaf
> There are no two identical leaves in the world.
>
> ```
> — Leibnitz
> ```
>[中文文档](./README_zh.md) | [English Document](./README.md)
## Introduce
A number segment pattern and Snowflake ID generator implemented in Go, based on the Kratos framework, suitable for this microservices framework and service discovery service.
The gRPC access performance is on par with Leaf.
> Interface compatible with Leaf, can be directly replaced
>
> Add the functionality to automatically reset the serial number every day (add the `auto_clean` field, intended for single-node use, with Nginx backup).
>
> Add an api to support remote addition of number segment tags.
>
> Add an api for bulk retrieval of number segments.
>
> Introduce a new UI interface that supports adding, viewing number segments, caching, and parsing Snowflake IDs.## Quick Start
### Segment Pattern
- table
```mysql
CREATE DATABASE leaf;CREATE TABLE `leaf_alloc` (
`biz_tag` varchar(128) NOT NULL DEFAULT '', -- your biz unique name
`max_id` bigint(20) NOT NULL DEFAULT '1',
`step` int(11) NOT NULL,
`description` varchar(256) DEFAULT NULL,
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`auto_clean` tinyint(1) default 0 null,
PRIMARY KEY (`biz_tag`)
) ENGINE=InnoDB;insert into leaf_alloc(biz_tag, max_id, step, description) values('leaf-segment-test', 1, 2000, 'Test leaf Segment Mode Get Id');
```- config
```yaml
data:
database:
segment_enable: true
table_name: "leaf_alloc"
driver: mysql
source: root:123@tcp(127.0.0.1:3306)/leaf?charset=utf8&parseTime=True&loc=Local
open_conn: 50
idle: 10
idle_timeout: 14400s
```- run
```
make build
bin/goLeaf -conf configs/config.yaml
```- api
```
curl http://localhost:8000/api/segment/get/leaf-segment-test// cache data
http://localhost:8000/monitor/cache
// db segment data
http://localhost:8000/monitor/db
```### Snowflake Pattern
- config
```yaml
data:
etcd:
snowflake_enable: true
# Enabling the functionality to synchronize and validate time with other Leaf nodes.
discovery_enable: false
endpoints: ["127.0.0.1:2379"]
dial_timeout: 2s
# When `discovery_enable` is enabled, the deviation in time among service nodes.
time_deviation: 50
```- api
```
curl http://localhost:8000/api/snowflake/get// decode ID
http://localhost:8000/decodeSnowflakeId
```### UI
addr:http:port/web
> 例如:http://127.0.0.1:8001/web
![DB号段](doc/image-20221101201529905.jpg)
---
![cache中的号段](doc/image-20221101201630411.jpg)
---
![雪花ID解析](doc/image-20221101201705230.png)