This commit is contained in:
Sense T 2024-04-09 11:36:34 +08:00
parent 613ef7fdd9
commit e18781ba25
2 changed files with 13 additions and 2 deletions

View File

@ -22,7 +22,7 @@ func (c *Controller) CreateDomain(d *models.Domain) (*models.Domain, error) {
} }
r := &models.RecordWithType[dns.SOARecord]{} r := &models.RecordWithType[dns.SOARecord]{}
r.Zone = fmt.Sprintf("%s.", d.DomainName) r.Zone = d.WithDotEnd()
r.Name = "@" r.Name = "@"
r.RecordType = models.RecordTypeSOA r.RecordType = models.RecordTypeSOA
r.Content.Ns = d.MainDNS r.Content.Ns = d.MainDNS

View File

@ -1,6 +1,9 @@
package models package models
import "strings" import (
"fmt"
"strings"
)
type Domain struct { type Domain struct {
ID int `gorm:"primaryKey" json:"id"` ID int `gorm:"primaryKey" json:"id"`
@ -21,3 +24,11 @@ func (d *Domain) EmailSOAForamt() string {
s[0] = strings.Replace(s[0], ".", "\\", -1) s[0] = strings.Replace(s[0], ".", "\\", -1)
return strings.Join(s, ".") return strings.Join(s, ".")
} }
func (d *Domain) WithDotEnd() string {
if strings.HasSuffix(d.DomainName, ".") {
return d.DomainName
} else {
return fmt.Sprintf("%s.", d.DomainName)
}
}