From c4d31818aa41af551b80579c192a4b2acff0f30d Mon Sep 17 00:00:00 2001 From: mark wu Date: Fri, 15 Dec 2023 17:07:09 +0800 Subject: [PATCH] Get TXT record with RandomID --- internal/models/domain_verification.go | 14 ++------------ internal/models/domain_verification_test.go | 4 ++-- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/internal/models/domain_verification.go b/internal/models/domain_verification.go index 654edbb..15af9af 100644 --- a/internal/models/domain_verification.go +++ b/internal/models/domain_verification.go @@ -1,9 +1,7 @@ package models import ( - "crypto/rand" "fmt" - "math/big" "time" ) @@ -22,14 +20,6 @@ type DomainVerification struct { } func NewDomainVerification(now time.Time, domain string, appID string) *DomainVerification { - num1, err := rand.Int(rand.Reader, big.NewInt(999999)) - if err != nil { - panic(err) - } - num2, err := rand.Int(rand.Reader, big.NewInt(999999)) - if err != nil { - panic(err) - } return &DomainVerification{ ID: newID("domain_verification"), CreatedAt: now, @@ -37,8 +27,8 @@ func NewDomainVerification(now time.Time, domain string, appID string) *DomainVe DeletedAt: nil, Domain: domain, AppID: appID, - DomainPrefix: fmt.Sprintf("%06d", num1), - Value: fmt.Sprintf("%06d", num2), + DomainPrefix: RandomID(4), + Value: RandomID(4), WillCheckAt: &now, LastCheckedAt: nil, } diff --git a/internal/models/domain_verification_test.go b/internal/models/domain_verification_test.go index b70dc16..b934280 100644 --- a/internal/models/domain_verification_test.go +++ b/internal/models/domain_verification_test.go @@ -11,6 +11,6 @@ import ( func TestDomainVerification(t *testing.T) { v := models.NewDomainVerification(time.Now(), "example.com", "appId") domain, value := v.GetTxtRecord() - assert.Regexp(t, "\\d{6}\\._pageship\\.example\\.com", domain) - assert.Regexp(t, "\\d{6}", value) + assert.Regexp(t, "\\w{7}\\._pageship\\.example\\.com", domain) + assert.Regexp(t, "\\w{7}", value) }