提交
This commit is contained in:
@@ -9,11 +9,11 @@ import (
|
||||
|
||||
// StoragePolicy 存储策略模型
|
||||
type StoragePolicy struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
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"`
|
||||
Config PolicyConfig `json:"config" gorm:"type:text"`
|
||||
Status int8 `json:"status" gorm:"default:1"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
@@ -48,16 +48,26 @@ type PolicyConfig struct {
|
||||
|
||||
// Value 实现 driver.Valuer 接口, 用于写入数据库
|
||||
func (c PolicyConfig) Value() (driver.Value, error) {
|
||||
return json.Marshal(c)
|
||||
b, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return string(b), nil
|
||||
}
|
||||
|
||||
// Scan 实现 sql.Scanner 接口, 用于从数据库读取
|
||||
// MySQL 返回 []byte, PostgreSQL/SQL Server 返回 string
|
||||
func (c *PolicyConfig) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
var bytes []byte
|
||||
switch v := value.(type) {
|
||||
case []byte:
|
||||
bytes = v
|
||||
case string:
|
||||
bytes = []byte(v)
|
||||
default:
|
||||
return fmt.Errorf("PolicyConfig.Scan: 无法将 %T 转换为 []byte", value)
|
||||
}
|
||||
return json.Unmarshal(bytes, c)
|
||||
|
||||
Reference in New Issue
Block a user