Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

fix: fix lint issue #10

Merged
merged 1 commit into from Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion uuid.go
Expand Up @@ -14,8 +14,13 @@ type UUID struct {
// V4 returns UUID V4 as string
func (u UUID) V4() string {
var uuid [16]byte
io.ReadFull(rand.Reader, uuid[:])

if _, err := io.ReadFull(rand.Reader, uuid[:]); err != nil {
panic(err)
}

uuid[6] = (uuid[6] & 0x0f) | 0x40 // Version 4
uuid[8] = (uuid[8] & 0x3f) | 0x80 // Variant is 10

return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:])
}
2 changes: 2 additions & 0 deletions uuid_test.go
Expand Up @@ -10,10 +10,12 @@ import (
func TestUUID_v4(t *testing.T) {
f := faker.NewFaker()
value := f.UUID().V4()

match, err := regexp.MatchString("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$", value)
if err != nil {
t.Fatal(err)
}

if !match {
t.Fatal("want true, got false")
}
Expand Down