Skip to content

Instantly share code, notes, and snippets.

@olekukonko
Created September 2, 2013 14:41
Show Gist options
  • Save olekukonko/6413580 to your computer and use it in GitHub Desktop.
Save olekukonko/6413580 to your computer and use it in GitHub Desktop.
Simple way to generate UUID in go
package main
import (
"os"
"fmt"
"log"
)
var Random *os.File
func init() {
f, err := os.Open("/dev/urandom")
if err != nil {
log.Fatal(err)
}
Random = f
}
func uuid() string {
b := make([]byte, 16)
Random.Read(b)
return fmt.Sprintf("%x-%x-%x-%x-%x",
b[0:4], b[4:6], b[6:8], b[8:10], b[10:])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment