From 305bab4f41abd9d6cd531c854e9b30d91f3b4548 Mon Sep 17 00:00:00 2001 From: lizhen Date: Mon, 30 Oct 2023 20:12:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Ereadme.en?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 84 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 25 deletions(-) diff --git a/README.en.md b/README.en.md index e95dfc4..e038ccd 100644 --- a/README.en.md +++ b/README.en.md @@ -1,36 +1,70 @@ # go-tinyid -#### Description -{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} +#### Introduction +This project mainly utilizes the Go language (go1.20) to implement an ID generator, and provides two access methods: HTTP and GRPC. +The generation algorithm used in the project is mainly based on the database number segment algorithm. You can refer to this algorithm for reference +[MeiTuan Left](https://tech.meituan.com/2017/04/21/mt-leaf.html)。 -#### Software Architecture -Software architecture description +#### Project Structure + main.go - Program entry, project initialization, and smooth server shutdown achieved + router - HTTP routing + controller - api controller + model - data model definition + dao - database operations + logic - logic operation + grpcserver - grpc server + idsequence - implemented data number segment generation algorithm + conf - the configures of database + common - common lib + config - viper config + dto - request response/return data structure + merrors - error number and error message + mysql - the connection pool of database + xgrpc - the proto defination of grpc server -#### Installation +#### Instructions For Use +1. The project is written using go1.20 and package management is carried out using go mod +2. build and run: go build && ./go-tinyid +3. The project provides two access methods: HTTP and GRPC, which can be chosen by oneself -1. xxxx -2. xxxx -3. xxxx +#### Core Process Description +##### 1. Define the ID generator structure +``` + type IdSequence struct { + idListLength int64 // 号段长度,可根据业务qps自行设置 + biz string // 业务类型 + ids chan int64 // 生成的id list, chan通道 + stopMonitor chan bool // 停止标志channel类型 + } +``` -#### Instructions +##### 2. The ID generator has three exposed methods: Monitor(), GetOne(), and Close(). + The Monitor method mainly monitors the ID list. When it is detected that the ID list is empty, + the add method will be called to add a new ID of idListLength to the ID list. During the process + of adding a new ID, MySQL optimistic locks will be used to prevent other processes from updating + the latest IDs obtained; + The GetOne method mainly obtains a new ID from the ID list; + The Close method mainly closes the channel and stops writing new IDs. -1. xxxx -2. xxxx -3. xxxx +##### 3. Data Table Structure +``` +create table if not exists test.sequence +( + id bigint unsigned auto_increment primary key, + biz varchar(128) default '' not null comment '业务类型', + value bigint default 0 not null comment 'id值', + version bigint default 0 not null comment '乐观锁', + is_del tinyint default 0 not null comment '是否软删标志', + create_time timestamp default CURRENT_TIMESTAMP not null comment '创建时间', + update_time timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP, + unique (version) +) charset = utf8mb4; +``` -#### Contribution +#### Participation Contribution +Welcome everyone to actively raise issues and jointly build the Golang version of tinyid -1. Fork the repository +1. Fork this project 2. Create Feat_xxx branch 3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +4. Create new Pull Request -- Gitee