Skip to content

mdigger/uuid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unique IDs in RFC 4122

GoDoc Build Status Coverage Status

Package uuid contains functions for creating and working with unique IDs in RFC 4122.

The main difference from other similar packages:

  1. support only versions of UUID V4;
  2. full support for serialization/deserialization to text and binary form, including JSON, BSON, XML and databases.
package main

import (
	"encoding/json"
	"log"

	"github.com/mdigger/uuid"
	"gopkg.in/mgo.v2/bson"
)

func main() {
	uuidData := uuid.New()
	println("UUID:   ", uuidData.String())
	data, err := json.Marshal(uuidData)
	if err != nil {
		log.Fatal(err)
	}
	println("JSON:  ", string(data))
	var newUUID uuid.UUID
	if err := json.Unmarshal(data, &newUUID); err != nil {
		log.Fatal(err)
	}
	println("RESTORE:", newUUID.String())
	data, err = bson.Marshal(uuidData)
	if err != nil {
		log.Fatal(err)
	}
	if err := bson.Unmarshal(data, &newUUID); err != nil {
		log.Fatal(err)
	}
	println("RESTORE:", newUUID.String())
}

About

Unique RFC 4122 IDs with MongoDB support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages