Skip to content

Instantly share code, notes, and snippets.

@cmdrkeene
Created October 29, 2014 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmdrkeene/6abefe35ad7f1fd3d2a2 to your computer and use it in GitHub Desktop.
Save cmdrkeene/6abefe35ad7f1fd3d2a2 to your computer and use it in GitHub Desktop.
uuid v4 and func to swap in test
var uuidFunc = uuidV4 // for swapping in test
func uuidV4() string {
b := make([]byte, 16)
_, err := io.ReadFull(rand.Reader, b)
if err != nil {
panic(err)
}
b[6] = (b[6] & 0x0F) | 0x40
b[8] = (b[8] &^ 0x40) | 0x80
return fmt.Sprintf("%x%x%x%x%x", b[: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