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:
@@ -2,8 +2,8 @@ package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.yoresee.cc/nightstar/ry/internal/model"
|
||||
)
|
||||
|
||||
type ProviderConfig struct {
|
||||
@@ -25,8 +25,8 @@ type Provider interface {
|
||||
}
|
||||
|
||||
type ServerService interface {
|
||||
List(ctx context.Context) ([]Server, error)
|
||||
Get(ctx context.Context, id string) (*Server, error)
|
||||
List(ctx context.Context) ([]model.Server, error)
|
||||
Get(ctx context.Context, id string) (*model.Server, error)
|
||||
Start(ctx context.Context, id string) error
|
||||
Stop(ctx context.Context, id string) error
|
||||
Reboot(ctx context.Context, id string) error
|
||||
@@ -37,96 +37,22 @@ type ServerService interface {
|
||||
}
|
||||
|
||||
type DomainService interface {
|
||||
List(ctx context.Context) ([]Domain, error)
|
||||
DNSList(ctx context.Context, domain string) ([]DNSRecord, error)
|
||||
DNSAdd(ctx context.Context, domain string, record DNSRecord) error
|
||||
List(ctx context.Context) ([]model.Domain, error)
|
||||
DNSList(ctx context.Context, domain string) ([]model.DNSRecord, error)
|
||||
DNSAdd(ctx context.Context, domain string, record model.DNSRecord) error
|
||||
DNSDelete(ctx context.Context, domain string, recordID string) error
|
||||
}
|
||||
|
||||
type StorageService interface {
|
||||
List(ctx context.Context) ([]StorageInstance, error)
|
||||
BucketList(ctx context.Context, instanceID string) ([]Bucket, error)
|
||||
List(ctx context.Context) ([]model.StorageInstance, error)
|
||||
BucketList(ctx context.Context, instanceID string) ([]model.Bucket, error)
|
||||
BucketCreate(ctx context.Context, instanceID, name string) error
|
||||
}
|
||||
|
||||
type CDNService interface {
|
||||
List(ctx context.Context) ([]CDNInstance, error)
|
||||
List(ctx context.Context) ([]model.CDNInstance, error)
|
||||
}
|
||||
|
||||
type BillingService interface {
|
||||
Orders(ctx context.Context) ([]Order, error)
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
ID string `json:"id" table:"ID"`
|
||||
Name string `json:"name" table:"NAME"`
|
||||
Status string `json:"status" table:"STATUS"`
|
||||
IP string `json:"ip" table:"IP"`
|
||||
CPU int `json:"cpu" table:"CPU"`
|
||||
Memory int `json:"memory" table:"MEM"`
|
||||
Disk int `json:"disk" table:"DISK"`
|
||||
OS string `json:"os" table:"OS"`
|
||||
Region string `json:"region" table:"REGION"`
|
||||
ExpireAt time.Time `json:"expires" table:"EXPIRES"`
|
||||
Raw any `json:"-"`
|
||||
}
|
||||
|
||||
type Domain struct {
|
||||
ID string `json:"id" table:"ID"`
|
||||
Name string `json:"name" table:"DOMAIN"`
|
||||
Status string `json:"status" table:"STATUS"`
|
||||
ExpireAt time.Time `json:"expires" table:"EXPIRES"`
|
||||
Raw any `json:"-"`
|
||||
}
|
||||
|
||||
type DNSRecord struct {
|
||||
ID string `json:"id" table:"ID"`
|
||||
Type string `json:"type" table:"TYPE"`
|
||||
Name string `json:"name" table:"NAME"`
|
||||
Value string `json:"value" table:"VALUE"`
|
||||
TTL int `json:"ttl" table:"TTL"`
|
||||
}
|
||||
|
||||
type StorageInstance struct {
|
||||
ID string `json:"id" table:"ID"`
|
||||
Name string `json:"name" table:"NAME"`
|
||||
Status string `json:"status" table:"STATUS"`
|
||||
Raw any `json:"-"`
|
||||
}
|
||||
|
||||
type Bucket struct {
|
||||
ID string `json:"id" table:"ID"`
|
||||
Name string `json:"name" table:"NAME"`
|
||||
Region string `json:"region" table:"REGION"`
|
||||
}
|
||||
|
||||
type CDNInstance struct {
|
||||
ID string `json:"id" table:"ID"`
|
||||
Domain string `json:"domain" table:"DOMAIN"`
|
||||
Status string `json:"status" table:"STATUS"`
|
||||
Raw any `json:"-"`
|
||||
}
|
||||
|
||||
type Order struct {
|
||||
ID string `json:"id" table:"ID"`
|
||||
Product string `json:"product" table:"PRODUCT"`
|
||||
Amount float64 `json:"amount" table:"AMOUNT"`
|
||||
Status string `json:"status" table:"STATUS"`
|
||||
Created time.Time `json:"created" table:"CREATED"`
|
||||
Raw any `json:"-"`
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
Code int
|
||||
Message string
|
||||
Detail string
|
||||
Raw []byte
|
||||
}
|
||||
|
||||
func (e *Error) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
func (e *Error) Debug() string {
|
||||
return fmt.Sprintf("%s\n%s", e.Detail, string(e.Raw))
|
||||
Orders(ctx context.Context) ([]model.Order, error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user