Files
NightStar bbba314127 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).
2026-07-28 19:31:22 +08:00

60 lines
1.4 KiB
Go

package rainyun
import (
"context"
"fmt"
"git.yoresee.cc/nightstar/ry/internal/model"
)
type StorageService struct {
client *client
}
func (s *StorageService) List(ctx context.Context) ([]model.StorageInstance, error) {
var raw []struct {
ID int `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
}
if err := s.client.getList(ctx, "/product/ros/instance", &raw); err != nil {
return nil, err
}
instances := make([]model.StorageInstance, len(raw))
for i, r := range raw {
instances[i] = model.StorageInstance{
ID: fmt.Sprintf("%d", r.ID),
Name: r.Name,
Raw: r,
}
}
return instances, nil
}
func (s *StorageService) BucketList(ctx context.Context, instanceID string) ([]model.Bucket, error) {
type rainyunBucket struct {
ID int `json:"id"`
Name string `json:"name"`
Region string `json:"region"`
}
var raw []rainyunBucket
path := fmt.Sprintf("/product/ros/bucket/%s", instanceID)
if err := s.client.get(ctx, path, &raw); err != nil {
return nil, err
}
buckets := make([]model.Bucket, len(raw))
for i, r := range raw {
buckets[i] = model.Bucket{
ID: fmt.Sprintf("%d", r.ID),
Name: r.Name,
}
}
return buckets, nil
}
func (s *StorageService) BucketCreate(ctx context.Context, instanceID, name string) error {
body := map[string]string{"name": name}
path := fmt.Sprintf("/product/ros/bucket/%s", instanceID)
return s.client.post(ctx, path, body, nil)
}