Guuid基于 HTTP-REST 的 UUID 生成服務(wù)
Guuid 是一款由 Go 語言開發(fā)的,基于 HTTP-REST 的 UUID 生成服務(wù)
UUID(Universally Unique Identifier)全局唯一標(biāo)識符,是指在一臺機(jī)器上生成的數(shù)字,它保證對在同一時(shí)空中的所有機(jī)器都是唯一的。
Guuid使用了服務(wù)器主機(jī)名、運(yùn)行的進(jìn)程ID、時(shí)間戳、隨機(jī)數(shù)、時(shí)序元素等一系列元素來保證生成UUID的唯一性。
UUID 16 bytes, 構(gòu)成:
4 bytes 主機(jī)名&進(jìn)程ID
4 bytes 時(shí)間戳
4 bytes 計(jì)數(shù)器
4 bytes 隨機(jī)數(shù)
安裝
$ go get -u github.com/dreamans/guuid/guuid-server $ cd $GOPATH/src/github.com/dreamans/guuid/guuid-server $ go install
運(yùn)行
$GOPATH/bin/guuid-server -port 11223 -timeout 3
Usage:
-port 運(yùn)行端口 -timeout 讀寫超時(shí)時(shí)間
運(yùn)行成功:
? http server started on [::]:11223
RestAPI
獲取UUID
$ curl http://127.0.0.1:11223/get
{
"code": 200,
"message": "OK",
"uuid": "5d1b3abf-5ab2-2792-0000-00046b2155a4"
}
批量獲取UUID
$ curl http://127.0.0.1:11223/mget/100
{
"code": 200,
"message": "OK",
"data": [
"5d1b3abf-5ab2-27cd-0000-00056d61a5e0",
"5d1b3abf-5ab2-27cd-0000-000648f72a80",
...
]
}
說明:
最多返回1000條記錄
獲取簡版UUID
$ curl http://127.0.0.1:11223/get/simple
{
"code": 200,
"message": "OK",
"uuid": "5d1b3abf5ab22792000000046b2155a4"
}
批量獲取簡版UUID
$ curl http://127.0.0.1:11223/mget/100/simple
{
"code": 200,
"message": "OK",
"data": [
"5d1b3abf5ab227cd000000056d61a5e0",
"5d1b3abf5ab227cd0000000648f72a80",
...
]
}
部署
LVS -> Nginx -> guuid-server
Configure Nginx
upstream guuid_server {
server localhost:11211;
server localhost:11212;
server localhost:11213;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://guuid_server;
}
}評論
圖片
表情
