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:
2026-07-28 19:31:22 +08:00
parent ccc9f27130
commit bbba314127
12 changed files with 127 additions and 112 deletions
+7 -7
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"time"
"git.yoresee.cc/nightstar/ry/internal/provider"
"git.yoresee.cc/nightstar/ry/internal/model"
)
// ServerService implements provider.ServerService for 雨云.
@@ -27,19 +27,19 @@ type rainyunServer struct {
ExpireDate int64 `json:"ExpDate"` // Unix timestamp
}
func (s *ServerService) List(ctx context.Context) ([]provider.Server, error) {
func (s *ServerService) List(ctx context.Context) ([]model.Server, error) {
var raw []rainyunServer
if err := s.client.getList(ctx, "/product/rcs/", &raw); err != nil {
return nil, err
}
servers := make([]provider.Server, len(raw))
servers := make([]model.Server, len(raw))
for i, r := range raw {
servers[i] = toServer(r)
}
return servers, nil
}
func (s *ServerService) Get(ctx context.Context, id string) (*provider.Server, error) {
func (s *ServerService) Get(ctx context.Context, id string) (*model.Server, error) {
var raw rainyunServer
path := fmt.Sprintf("/product/rcs/%s/", id)
if err := s.client.get(ctx, path, &raw); err != nil {
@@ -85,10 +85,10 @@ func (s *ServerService) Upgrade(ctx context.Context, id, plan string) error {
return s.client.post(ctx, fmt.Sprintf("/product/rcs/%s/upgrade", id), body, nil)
}
// toServer maps a rainyunServer to the provider.Server model.
func toServer(r rainyunServer) provider.Server {
// toServer maps a rainyunServer to the model.Server model.
func toServer(r rainyunServer) model.Server {
expire := time.Unix(r.ExpireDate, 0)
return provider.Server{
return model.Server{
ID: fmt.Sprintf("%d", r.ID),
Name: r.Name,
Status: r.Status,