github.com/dahs81/otto@v0.2.1-0.20160126165905-6400716cf085/helper/uuid/uuid.go (about) 1 package uuid 2 3 import ( 4 "crypto/rand" 5 "fmt" 6 ) 7 8 // GenerateUUID is used to generate a random UUID 9 func GenerateUUID() string { 10 buf := make([]byte, 16) 11 if _, err := rand.Read(buf); err != nil { 12 panic(fmt.Errorf("failed to read random bytes: %v", err)) 13 } 14 15 return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x", 16 buf[0:4], 17 buf[4:6], 18 buf[6:8], 19 buf[8:10], 20 buf[10:16]) 21 }