GithubHelp home page GithubHelp logo

younglifestyle / goleaf Goto Github PK

View Code? Open in Web Editor NEW
78.0 9.0 14.0 403 KB

golang leaf,REF. Meituan-Dianping Leaf,ID发号器

License: Apache License 2.0

Dockerfile 0.86% Makefile 2.99% Go 85.59% HTML 10.56%
go-kratos leaf golang kratos

goleaf's Introduction

Leaf

There are no two identical leaves in the world.

— Leibnitz

中文文档 | English Document

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
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
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
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号段


cache中的号段


雪花ID解析

goleaf's People

Contributors

osgochina avatar younglifestyle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.