- 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).
77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package rainyun
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.yoresee.cc/nightstar/ry/internal/model"
|
|
)
|
|
|
|
type DomainService struct {
|
|
client *client
|
|
}
|
|
|
|
type rainyunDomain struct {
|
|
ID int `json:"id"`
|
|
DomainName string `json:"domain_name"`
|
|
Status string `json:"status"`
|
|
ExpireDate string `json:"expire_date"`
|
|
}
|
|
|
|
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([]model.Domain, len(raw))
|
|
for i, r := range raw {
|
|
domains[i] = model.Domain{
|
|
ID: fmt.Sprintf("%d", r.ID),
|
|
Name: r.DomainName,
|
|
}
|
|
}
|
|
return domains, nil
|
|
}
|
|
|
|
func (d *DomainService) DNSList(ctx context.Context, domain string) ([]model.DNSRecord, error) {
|
|
type rainyunDNSRecord struct {
|
|
ID int `json:"id"`
|
|
RecordType string `json:"record_type"`
|
|
Host string `json:"host"`
|
|
Value string `json:"value"`
|
|
TTL int `json:"ttl"`
|
|
}
|
|
var raw []rainyunDNSRecord
|
|
path := fmt.Sprintf("/product/domain/%s/dns/", domain)
|
|
if err := d.client.get(ctx, path, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
records := make([]model.DNSRecord, len(raw))
|
|
for i, r := range raw {
|
|
records[i] = model.DNSRecord{
|
|
ID: fmt.Sprintf("%d", r.ID),
|
|
Type: r.RecordType,
|
|
Name: r.Host,
|
|
Value: r.Value,
|
|
TTL: r.TTL,
|
|
}
|
|
}
|
|
return records, nil
|
|
}
|
|
|
|
func (d *DomainService) DNSAdd(ctx context.Context, domain string, record model.DNSRecord) error {
|
|
body := map[string]any{
|
|
"record_type": record.Type,
|
|
"host": record.Name,
|
|
"value": record.Value,
|
|
"ttl": record.TTL,
|
|
}
|
|
path := fmt.Sprintf("/product/domain/%s/dns", domain)
|
|
return d.client.post(ctx, path, body, nil)
|
|
}
|
|
|
|
func (d *DomainService) DNSDelete(ctx context.Context, domain string, recordID string) error {
|
|
path := fmt.Sprintf("/product/domain/%s/dns/%s", domain, recordID)
|
|
return d.client.delete(ctx, path, nil)
|
|
}
|