long options supported

This commit is contained in:
Sense T
2024-04-11 10:51:50 +08:00
parent c3b80093d2
commit 7a5fcf1972
10 changed files with 108 additions and 58 deletions

View File

@@ -12,13 +12,13 @@ type Domain struct {
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"`
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"`
}
func (d Domain) EmailSOAForamt() string {
@@ -38,7 +38,7 @@ func (d Domain) WithDotEnd() string {
}
}
func (d *Domain) GenerateSOA() dns.SOARecord {
func (d Domain) GenerateSOA() dns.SOARecord {
var ns string
if !strings.HasSuffix(d.MainDNS, ".") {
ns = fmt.Sprintf("%s.", d.MainDNS)
@@ -54,3 +54,9 @@ func (d *Domain) GenerateSOA() dns.SOARecord {
MinTtl: d.NegativeTtl,
}
}
type IDomain interface {
EmailSOAForamt() string
WithDotEnd() string
GenerateSOA() dns.SOARecord
}

View File

@@ -22,7 +22,7 @@ const (
RecordTypeSRV = "SRV"
)
type RecordContentDefault any
type RecordContentDefault map[string]any
type recordContentTypes interface {
dns.ARecord | dns.AAAARecord | dns.CNAMERecord | dns.CAARecord | dns.NSRecord | dns.MXRecord | dns.SOARecord | dns.SRVRecord | dns.TXTRecord | RecordContentDefault
@@ -30,11 +30,11 @@ type recordContentTypes interface {
type Record[T recordContentTypes] struct {
ID int `gorm:"primaryKey" json:"id"`
Zone string `gorm:"not null,size:255" json:"zone"`
Name string `gorm:"not null,size:255" json:"name"`
Zone string `gorm:"not null;size:255" json:"zone"`
Name string `gorm:"not null;size:255" json:"name"`
Ttl int `json:"ttl"`
Content T `gorm:"serializer:json,type:\"text\"" json:"content"`
RecordType string `gorm:"not null,size:255" json:"record_type"`
Content T `gorm:"serializer:json;type:text" json:"content"`
RecordType string `gorm:"not null;size:255" json:"record_type"`
}
func (Record[T]) TableName() string {

View File

@@ -1,6 +1,10 @@
package models
import "gorm.io/gorm"
import (
"fmt"
"gorm.io/gorm"
)
const (
SettingsKeyAdminUsername = "admin.username"
@@ -10,6 +14,14 @@ const (
type Settings struct {
gorm.Model
Key string `gorm:"unique,not null,size:255"`
Value string `gorm:"not null,size:255"`
Key string `gorm:"unique;not null;size:255"`
Value string `gorm:"not null;size:255"`
}
func (s Settings) String() string {
return fmt.Sprintf("%s: %s", s.Key, s.Value)
}
type ISettings interface {
String() string
}