test stage 1

This commit is contained in:
Sense T
2024-04-19 09:44:37 +08:00
parent b583720223
commit 88b2255f8b
20 changed files with 131 additions and 95 deletions

View File

@@ -6,17 +6,17 @@ import (
)
type Domain struct {
ID int `gorm:"primaryKey" json:"id"`
ID uint `gorm:"primaryKey" json:"id"`
DomainName string `gorm:"unique,not null,size:255" json:"domain_name"`
//SOA Info
MainDNS string `gorm:"not null;size:255" json:"main_dns"`
AdminEmail string `gorm:"not null;size:255" json:"admin_email"`
SerialNumber int64 `gorm:"not null;default:1" json:"serial_number"`
RefreshInterval uint32 `gorm:"not null;size:255,default:\"86400\"" json:"refresh_interval"`
RetryInterval uint32 `gorm:"not null;size:255,default:\"7200\"" json:"retry_interval"`
ExpiryPeriod uint32 `gorm:"not null;size:255,default:\"3600000\"" json:"expiry_period"`
NegativeTtl uint32 `gorm:"not null;size:255,default:\"86400\"" json:"negative_ttl"`
RefreshInterval uint32 `gorm:"type:uint;not null;default:86400" json:"refresh_interval"`
RetryInterval uint32 `gorm:"type:uint;not null;default:7200" json:"retry_interval"`
ExpiryPeriod uint32 `gorm:"type:uint;not null;default:3600000" json:"expiry_period"`
NegativeTtl uint32 `gorm:"type:uint;not null;default:86400" json:"negative_ttl"`
}
func (d *Domain) EmailSOAForamt() string {
@@ -53,8 +53,13 @@ func (d *Domain) GenerateSOA() SOARecord {
return r
}
func (d *Domain) GetValue() Domain {
return *d
}
type IDomain interface {
EmailSOAForamt() string
WithDotEnd() string
GenerateSOA() SOARecord
GetValue() Domain
}

View File

@@ -25,7 +25,7 @@ type recordContentTypes interface {
}
type Record[T recordContentTypes] struct {
ID int `gorm:"primaryKey" json:"id"`
ID uint `gorm:"primaryKey" json:"id"`
Zone string `gorm:"not null;size:255" json:"zone"`
Name string `gorm:"not null;size:255" json:"name"`
Ttl int `json:"ttl"`
@@ -34,11 +34,11 @@ type Record[T recordContentTypes] struct {
}
func (*Record[T]) TableName() string {
return "coredns_record"
return "coredns_records"
}
func (r *Record[T]) CheckZone() error {
if strings.HasSuffix(r.Zone, ".") {
if !strings.HasSuffix(r.Zone, ".") {
return ErrorZoneNotEndWithDot
}
return nil
@@ -65,6 +65,10 @@ func (r *Record[T]) GetType() string {
return r.RecordType
}
func (r *Record[T]) GetValue() IRecord {
return r.ToEntity()
}
type IRecord interface {
TableName() string
CheckZone() error
@@ -72,4 +76,5 @@ type IRecord interface {
ToEntity() IRecord
FromEntity(any) error
GetType() string
GetValue() IRecord
}

View File

@@ -2,8 +2,6 @@ package models
import (
"fmt"
"gorm.io/gorm"
)
const (
@@ -13,7 +11,7 @@ const (
)
type Settings struct {
gorm.Model
ID uint `gorm:"primaryKey"`
Key string `gorm:"unique;not null;size:255"`
Value string `gorm:"not null;size:255"`
}
@@ -22,6 +20,11 @@ func (s *Settings) String() string {
return fmt.Sprintf("%s: %s", s.Key, s.Value)
}
func (s *Settings) GetValue() Settings {
return *s
}
type ISettings interface {
String() string
GetValue() Settings
}