Guuid: 由 Go 語言開發的 UUID 生成服務

Guuid 是一款由 Go 語言開發的,基於HTTP的REST的 UUID 生成服務git

Github:https://github.com/dreamans/g...github

UUID(Universally Unique Identifier)全局惟一標識符,是指在一臺機器上生成的數字,它保證對在同一時空中的全部機器都是惟一的。服務器

Guuid使用了服務器主機名、運行的進程ID、時間戳、隨機數、時序元素等一系列元素來保證生成UUID的惟一性。curl

UUID 16 bytes, 構成:ui

  • 4 bytes 主機名&進程ID
  • 4 bytes 時間戳
  • 4 bytes 計數器
  • 4 bytes 隨機數

安裝

$ go get -u github.com/dreamans/guuid/guuid-server
$ cd $GOPATH/src/github.com/dreamans/guuid/guuid-server
$ go install

運行

$GOPATH/bin/guuid-server -port 11223 -timeout 3

Usage:url

-port 運行端口

-timeout 讀寫超時時間

運行成功:spa

⇨ 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-servercode

guuid-server.png

  • 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;
    }
}
相關文章
相關標籤/搜索