From f8c203888aaab85545b90d574ac41c8e7026cf68 Mon Sep 17 00:00:00 2001 From: Sasha Melentyev Date: Sun, 26 Jun 2022 11:50:46 +0300 Subject: [PATCH] fix: fix lint issue --- uuid.go | 7 ++++++- uuid_test.go | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/uuid.go b/uuid.go index 15e49f8..64e4cf6 100644 --- a/uuid.go +++ b/uuid.go @@ -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:]) } diff --git a/uuid_test.go b/uuid_test.go index 0ddc9ab..8e6b901 100644 --- a/uuid_test.go +++ b/uuid_test.go @@ -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") }