package model import ( "database/sql/driver" "encoding/json" "fmt" "time" ) // StoragePolicy 存储策略模型 type StoragePolicy struct { ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"` Name string `json:"name" gorm:"size:64;not null"` Type string `json:"type" gorm:"size:32;not null"` // local/minio/s3/oss PolicyType string `json:"policy_type" gorm:"size:32;default:hot"` // hot/cold/public/slave Config PolicyConfig `json:"config" gorm:"type:json"` Status int8 `json:"status" gorm:"default:1"` CreatedAt time.Time `json:"created_at"` } // TableName 指定表名 func (StoragePolicy) TableName() string { return "fs_storage_policy" } // PolicyConfig 存储策略配置 type PolicyConfig struct { // 本地存储配置 BasePath string `json:"base_path,omitempty"` // MinIO/S3/OSS 配置 Endpoint string `json:"endpoint,omitempty"` Bucket string `json:"bucket,omitempty"` AccessKey string `json:"access_key,omitempty"` SecretKey string `json:"secret_key,omitempty"` Region string `json:"region,omitempty"` UseSSL bool `json:"use_ssl,omitempty"` // 访问模式配置 AccessMode string `json:"access_mode,omitempty"` // proxy=中转模式, presigned=预签名直连, 默认proxy // Nginx代理MinIO的地址(预签名模式下, 替换MinIO内部地址为Nginx公网地址) NginxEndpoint string `json:"nginx_endpoint,omitempty"` // 如 http://files.example.com // 中转模式下是否启用X-Sendfile UseXSendfile bool `json:"use_x_sendfile,omitempty"` // X-Sendfile对应的Nginx内部路径 XSendfilePath string `json:"x_sendfile_path,omitempty"` // 如 /minio-files } // Value 实现 driver.Valuer 接口, 用于写入数据库 func (c PolicyConfig) Value() (driver.Value, error) { return json.Marshal(c) } // Scan 实现 sql.Scanner 接口, 用于从数据库读取 func (c *PolicyConfig) Scan(value interface{}) error { if value == nil { return nil } bytes, ok := value.([]byte) if !ok { return fmt.Errorf("PolicyConfig.Scan: 无法将 %T 转换为 []byte", value) } return json.Unmarshal(bytes, c) }