Skip to content

Instantly share code, notes, and snippets.

@dedalqq
Last active September 23, 2018 14:35
Embed
What would you like to do?
Simple generation UUID in golang
package main
import (
"encoding/hex"
"fmt"
"math/rand"
"time"
)
func uuid() string {
token := make([]byte, 18)
rand.Read(token)
result := make([]byte, 36)
hex.Encode(result, token)
result[8] = 45
result[13] = 45
result[18] = 45
result[23] = 45
return string(result)
}
func main() {
rand.Seed(time.Now().UnixNano()) // optional
fmt.Println(uuid()) // 0c204d39-00fd-d3f1-20ca-007e91c7d029
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment