You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

github.com/mdigger/uuid

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/mdigger/uuid

v0.0.0-20180831143433-892ae55ef6e4
Source
Go
Version published
Created
Source

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:

  • support only versions of UUID V4;
  • 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())
}

FAQs

Package last updated on 31 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts