Skip to content

Commit

Permalink
Get TXT record with RandomID
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkRunWu committed Dec 15, 2023
1 parent 11bf4bc commit c4d3181
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
14 changes: 2 additions & 12 deletions internal/models/domain_verification.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package models

import (
"crypto/rand"
"fmt"
"math/big"
"time"
)

Expand All @@ -22,23 +20,15 @@ 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,
UpdatedAt: now,
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,
}
Expand Down
4 changes: 2 additions & 2 deletions internal/models/domain_verification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit c4d3181

Please sign in to comment.