refactor: replace SQLite/GORM with JSON file storage

- Remove GORM and SQLite, use simple JSON file (data/certs.json) for persistence
- CertStore with sync.RWMutex for thread-safe in-memory cache
- All handlers updated to use config.Store instead of config.DB
- Cron job and stats updated accordingly
- go mod tidy removes unused gorm/sqlite dependencies
This commit is contained in:
2026-05-12 15:27:10 +08:00
parent d0e738e1ef
commit 3fa77d9bc0
6 changed files with 292 additions and 164 deletions
+15 -23
View File
@@ -1,33 +1,25 @@
package config
import (
"time"
"gorm.io/gorm"
)
import "time"
type Certificate struct {
ID uint `gorm:"primarykey" json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
ID uint `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Domain string `json:"domain" gorm:"uniqueIndex;size:255"`
Email string `json:"email" gorm:"size:255"`
Provider string `json:"provider" gorm:"size:50;default:letsencrypt"` // letsencrypt, zerossl
ChallengeType string `json:"challenge_type" gorm:"size:20;default:http"` // http, dns
DNSProvider string `json:"dns_provider,omitempty" gorm:"size:50"` // alidns, cloudflare, etc.
DNSConfig string `json:"dns_config,omitempty" gorm:"type:text"` // JSON config for DNS provider
Domain string `json:"domain"`
Email string `json:"email"`
Provider string `json:"provider"` // letsencrypt, zerossl
ChallengeType string `json:"challenge_type"` // http, dns
DNSProvider string `json:"dns_provider,omitempty"` // alidns, cloudflare, etc.
DNSConfig string `json:"dns_config,omitempty"` // JSON config for DNS provider
Status string `json:"status" gorm:"size:20;default:pending"` // pending, active, expired, error
CertURL string `json:"cert_url,omitempty" gorm:"size:512"`
Status string `json:"status"` // pending, active, expired, error
CertURL string `json:"cert_url,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
LastRenewedAt *time.Time `json:"last_renewed_at,omitempty"`
ErrorMessage string `json:"error_message,omitempty" gorm:"type:text"`
ErrorMessage string `json:"error_message,omitempty"`
// Auto renew settings
AutoRenew bool `json:"auto_renew" gorm:"default:true"`
RenewDays int `json:"renew_days" gorm:"default:30"` // Renew when expires within this many days
// ACME account key
AccountKeyID uint `json:"account_key_id,omitempty"`
AutoRenew bool `json:"auto_renew"`
RenewDays int `json:"renew_days"` // Renew when expires within this many days
}