linux中uuid生成器,Go UUIDv4 库基于Linux kernel UUID生成器

go-uuid - A wrapper for Linux kernel UUID v4 generator.

625332134c6f4d4600884b99daebf603.png625332134c6f4d4600884b99daebf603.png

This UUID library is an yet another attempt to reimplement the wheel, but instead of outstanding algorithm it wraps the Linux kernel implementation of UUID v4 generator.

Installation

The latest version can be installed using go tool:

go get github.com/ybubnov/go-uuid

Usage

Trivial configuration

The usage is pretty straightforward. Here is the most trivial example:

package main

import (

"fmt"

"github.com/ybubnov/go-uuid"

)

func main() {

u1 := uuid.New()

fmt.Printf("uuid v4: %s\n", u1)

}

Advanced configuration

Another example shows an advanced configuration of generator. It defines the 128 buffered UUIDs, and 16 workers used to produce them.

package main

import (

"fmt"

"github.com/ybubnov/go-uuid"

)

func main() {

src := uuid.Kernel{MaxIdle: 128, MaxProcs: 16}

defer src.Stop() // Terminate source when time comes.

u1, err := src.Next()

if err != nil {

fmt.Printf("failed to generate uuid: %s\n", err)

}

fmt.Printf("uuid v4: %s\n", u1)

}

Licence

The UUID library is distributed under MIT license, therefore you are free to do with code whatever you want. See the LICENSE file for full license text.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值