-
-
Save olekukonko/6413580 to your computer and use it in GitHub Desktop.
Simple way to generate UUID in go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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