58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package dataset
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"gitlink.org.cn/JointCloud/pcm-participant-ai/common"
|
|
)
|
|
|
|
type Search struct {
|
|
}
|
|
|
|
type CreateParam struct {
|
|
Name string `json:"name" binding:"required"`
|
|
Desc string `json:"desc"`
|
|
Src *common.Source `json:"src,omitempty"`
|
|
Param CreateParameter `json:"param,omitempty"`
|
|
}
|
|
|
|
type OpenI struct {
|
|
Repo string `json:"repo,omitempty"`
|
|
}
|
|
|
|
func (o OpenI) DatasetCreateParam() {
|
|
}
|
|
|
|
func (cp *CreateParam) UnmarshalJSON(data []byte) error {
|
|
// 临时结构体:用于捕获原始 JSON 中的 param 字段数据
|
|
type TempCreateParam struct {
|
|
Name string `json:"name"`
|
|
Desc string `json:"desc"`
|
|
Src *common.Source `json:"src,omitempty"`
|
|
Param json.RawMessage `json:"param,omitempty"` // 捕获原始 JSON 数据
|
|
}
|
|
var temp TempCreateParam
|
|
if err := json.Unmarshal(data, &temp); err != nil {
|
|
return err
|
|
}
|
|
|
|
// 将临时结构体的字段赋值给原结构体(除 Param 外)
|
|
cp.Name = temp.Name
|
|
cp.Desc = temp.Desc
|
|
cp.Src = temp.Src
|
|
|
|
// 解析 param 字段的原始数据为具体类型
|
|
if temp.Param != nil {
|
|
// 尝试解析为 OpenI 类型
|
|
var openi OpenI
|
|
if err := json.Unmarshal(temp.Param, &openi); err == nil {
|
|
cp.Param = &openi
|
|
return nil
|
|
}
|
|
|
|
return fmt.Errorf("unsupported param type in CreateParam")
|
|
}
|
|
|
|
return nil
|
|
}
|