项目作者: gbrlsnchs

项目描述 :
Go UUID generator
高级语言: Go
项目地址: git://github.com/gbrlsnchs/uuid.git
创建时间: 2018-08-28T16:48:31Z
项目社区:https://github.com/gbrlsnchs/uuid

开源协议:MIT License

下载


uuid (Universally Unique IDentifier generator for Go)

Build Status
Sourcegraph
GoDoc
Minimal Version

About

This package is a UUID (or GUID) generator for Go.

Supported versions:

Version Supported
1 :heavy_check_mark:
2 :heavy_check_mark:
3 :heavy_check_mark:
4 :heavy_check_mark:
5 :heavy_check_mark:

Usage

Full documentation here.

Installing

Go 1.10

vgo get -u github.com/gbrlsnchs/uuid

Go 1.11 or after

go get -u github.com/gbrlsnchs/uuid

Importing

  1. import (
  2. // ...
  3. "github.com/gbrlsnchs/uuid"
  4. )

Example

Generating UUIDs

  1. guid := uuid.V4(nil) // panics if there's an error
  2. log.Printf("guid = %v", guid) // prints a 36-byte hex-encoded UUID
  3. log.Printf("guid version = %v", guid.Version()) // prints "Version 4"
  4. log.Printf("guid variant = %v", guid.Variant()) // prints "RFC 4122"

Building UUIDs from strings

  1. guid, err := uuid.Parse("d9ab3f01-482f-425d-8a10-a24b0abfe661")
  2. if err != nil {
  3. // handle error
  4. }
  5. log.Print(guid.String()) // prints "d9ab3f01-482f-425d-8a10-a24b0abfe661"
  6. log.Print(guid.GUID()) // prints "{d9ab3f01-482f-425d-8a10-a24b0abfe661}"
  7. log.Print(guid.Version().String()) // prints "Version 4"
  8. log.Print(guid.Variant().String()) // prints "RFC 4122"

Contributing

How to help