File: uuid.go

package info (click to toggle)
golang-github-hashicorp-uuid 0.0~git20160218.0.6994546-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 88 kB
  • ctags: 5
  • sloc: makefile: 2
file content (21 lines) | stat: -rw-r--r-- 372 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package uuid

import (
	"crypto/rand"
	"fmt"
)

// GenerateUUID is used to generate a random UUID
func GenerateUUID() string {
	buf := make([]byte, 16)
	if _, err := rand.Read(buf); err != nil {
		panic(fmt.Errorf("failed to read random bytes: %v", err))
	}

	return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x",
		buf[0:4],
		buf[4:6],
		buf[6:8],
		buf[8:10],
		buf[10:16])
}