refactor: extract domain models from provider into internal/model
- Move Server/Domain/DNSRecord/Bucket/StorageInstance/CDNInstance/Order/Error structs to internal/model/ - Provider interfaces now reference model.* types - Rainyun provider implementations import model package for data types - CLI commands updated to use model.DNSRecord directly Separates pure data structures from service contract interfaces, following hexagonal architecture: models (entities) live independently from ports (provider interfaces) and adapters (rainyun/* implementations).
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.yoresee.cc/nightstar/ry/internal/provider"
|
||||
"git.yoresee.cc/nightstar/ry/internal/model"
|
||||
)
|
||||
|
||||
type DomainService struct {
|
||||
@@ -18,14 +18,14 @@ type rainyunDomain struct {
|
||||
ExpireDate string `json:"expire_date"`
|
||||
}
|
||||
|
||||
func (d *DomainService) List(ctx context.Context) ([]provider.Domain, error) {
|
||||
func (d *DomainService) List(ctx context.Context) ([]model.Domain, error) {
|
||||
var raw []rainyunDomain
|
||||
if err := d.client.getList(ctx, "/product/domain/", &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
domains := make([]provider.Domain, len(raw))
|
||||
domains := make([]model.Domain, len(raw))
|
||||
for i, r := range raw {
|
||||
domains[i] = provider.Domain{
|
||||
domains[i] = model.Domain{
|
||||
ID: fmt.Sprintf("%d", r.ID),
|
||||
Name: r.DomainName,
|
||||
}
|
||||
@@ -33,7 +33,7 @@ func (d *DomainService) List(ctx context.Context) ([]provider.Domain, error) {
|
||||
return domains, nil
|
||||
}
|
||||
|
||||
func (d *DomainService) DNSList(ctx context.Context, domain string) ([]provider.DNSRecord, error) {
|
||||
func (d *DomainService) DNSList(ctx context.Context, domain string) ([]model.DNSRecord, error) {
|
||||
type rainyunDNSRecord struct {
|
||||
ID int `json:"id"`
|
||||
RecordType string `json:"record_type"`
|
||||
@@ -46,9 +46,9 @@ func (d *DomainService) DNSList(ctx context.Context, domain string) ([]provider.
|
||||
if err := d.client.get(ctx, path, &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
records := make([]provider.DNSRecord, len(raw))
|
||||
records := make([]model.DNSRecord, len(raw))
|
||||
for i, r := range raw {
|
||||
records[i] = provider.DNSRecord{
|
||||
records[i] = model.DNSRecord{
|
||||
ID: fmt.Sprintf("%d", r.ID),
|
||||
Type: r.RecordType,
|
||||
Name: r.Host,
|
||||
@@ -59,7 +59,7 @@ func (d *DomainService) DNSList(ctx context.Context, domain string) ([]provider.
|
||||
return records, nil
|
||||
}
|
||||
|
||||
func (d *DomainService) DNSAdd(ctx context.Context, domain string, record provider.DNSRecord) error {
|
||||
func (d *DomainService) DNSAdd(ctx context.Context, domain string, record model.DNSRecord) error {
|
||||
body := map[string]any{
|
||||
"record_type": record.Type,
|
||||
"host": record.Name,
|
||||
|
||||
Reference in New Issue
Block a user