feat: domain/storage/billing/config cmds + rainyun domain/storage/billing services
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package rainyun
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.yoresee.cc/nightstar/ry/internal/provider"
|
||||
)
|
||||
|
||||
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) ([]provider.Domain, error) {
|
||||
var raw []rainyunDomain
|
||||
if err := d.client.get(ctx, "/product/domain/", &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
domains := make([]provider.Domain, len(raw))
|
||||
for i, r := range raw {
|
||||
domains[i] = provider.Domain{
|
||||
ID: fmt.Sprintf("%d", r.ID),
|
||||
Name: r.DomainName,
|
||||
}
|
||||
}
|
||||
return domains, nil
|
||||
}
|
||||
|
||||
func (d *DomainService) DNSList(ctx context.Context, domain string) ([]provider.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([]provider.DNSRecord, len(raw))
|
||||
for i, r := range raw {
|
||||
records[i] = provider.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 provider.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)
|
||||
}
|
||||
Reference in New Issue
Block a user