6 Star 5 Fork 0

他乡启程 / seqsvr

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 2.00 KB
一键复制 编辑 原始数据 按行查看 历史
他乡启程 提交于 2018-07-27 16:36 . add english readme

SEQSVR

High performance unique number generator powered by Go

中文 README

Features

  • Distributed: Can be scaled horizontally
  • High performance: Allocation ID only accesses memory (up to the upper limit will request the database once)
  • Ease of use: Provide as HTTP service
  • Unique: MySQL auto increment ID, never repeat

Requirement

We are using these awesome projects as necessary libraries.

  • gopkg.in/yaml.v2
  • github.com/go-sql-driver/mysql
  • github.com/satori/go.uuid

Installation

You can install this service in the following three ways.

Note: You need to create the database and modify the configuration of the database in the configuration file before starting.

go get:

go get github.com/qichengzx/seqsvr
seqsvr

Compile By Yourself:

git clone git@github.com:qichengzx/seqsvr.git
cd seqsvr
go build .
./seqsvr

Docker:

The Docker "multi-stage" build feature is used, be ensure the Docker version is 17.05 or above. See:Use multi-stage builds

git clone git@github.com:qichengzx/seqsvr.git
cd seqsvr
docker build seqsvr:latest .
docker run -p 8000:8000 seqsvr:latest

Create Database

The database name can be customized, modify config.yml.

Then import the following SQL to generate the data table.

CREATE TABLE `generator_table` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `uuid` char(36) NOT NULL COMMENT 'Machine identification',
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_UNIQUE` (`id`),
  UNIQUE KEY `stub_UNIQUE` (`uuid`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Configuration

The configuration file is using YAML.

#app
port: ':8000'

#service
step: 100

#db
mysql:
  user: 'root'
  password: ''
  host: 'tcp(localhost:3306)'
  database: 'sequence'
  maxidle: 2
  maxopen: 10

Usage

curl http://localhost:8000/new

{"code":0,"msg":"ok","data":{"id":101}}
Go
1
https://gitee.com/qichengzx/seqsvr.git
git@gitee.com:qichengzx/seqsvr.git
qichengzx
seqsvr
seqsvr
master

搜索帮助