github.com/qiniu/go-sdk/v7@v7.27.0/media/apis/prefop/api.go (about)

     1  // THIS FILE IS GENERATED BY api-generator, DO NOT EDIT DIRECTLY!
     2  
     3  // 查询持久化数据处理命令的执行状态
     4  package prefop
     5  
     6  import (
     7  	"encoding/json"
     8  
     9  	credentials "github.com/qiniu/go-sdk/v7/storagev2/credentials"
    10  	errors "github.com/qiniu/go-sdk/v7/storagev2/errors"
    11  )
    12  
    13  // 调用 API 所用的请求
    14  type Request struct {
    15  	PersistentId string                          // 持久化数据处理任务 ID
    16  	Credentials  credentials.CredentialsProvider // 鉴权参数,用于生成鉴权凭证,如果为空,则使用 HTTPClientOptions 中的 CredentialsProvider
    17  }
    18  
    19  // 获取 API 所用的响应
    20  type Response struct {
    21  	PersistentId string        // 持久化数据处理任务 ID
    22  	Code         int64         // 持久化数据处理任务状态码
    23  	Description  string        // 与状态码相对应的详细描述
    24  	ObjectName   string        // 源对象名称
    25  	BucketName   string        // 源空间名称
    26  	Pipeline     string        // 云处理操作的处理队列
    27  	TaskFrom     string        // 如果没有,则表示通过 `api+fops` 命令提交的任务,否则遵循规则 `<source>: <source_id>`,其中 `<source>` 当前可选 `workflow` 或 `trigger`
    28  	RequestId    string        // 云处理请求的请求 ID
    29  	Type         int64         // 任务类型,支持 `0` 表示普通任务,`1` 表示闲时任务
    30  	CreatedAt    string        // 任务创建时间
    31  	Items        PfopTaskItems // 云处理操作列表
    32  }
    33  
    34  // 云处理结果的外链对象名称
    35  type ObjectNames = []string
    36  
    37  // 返回的持久化数据处理任务中的云处理操作状态
    38  type PfopTaskItem struct {
    39  	Command     string      // 云操作命令
    40  	Code        int64       // 云操作状态码
    41  	Description string      // 与状态码相对应的详细描述
    42  	Error       string      // 如果处理失败,该字段会给出失败的详细原因
    43  	ErrorIndex  int64       // 如果处理失败,该字段会给出错误的管道顺序,从0开始,0表示第一段,以此类推。
    44  	Hash        string      // 云处理结果保存在服务端的唯一标识
    45  	ObjectName  string      // 云处理结果的外链对象名称
    46  	Result      interface{} // 当 object_name 和 object_names 都不存在时,此字段会有值,返回 cmd 的处理结果
    47  	ObjectNames ObjectNames // 当 cmd 返回多项结果时,此字段会有值,返回云处理结果的外链对象名称列表
    48  	ReturnOld   int64       // 是否返回了旧的数据
    49  }
    50  type jsonPfopTaskItem struct {
    51  	Command     string      `json:"cmd"`                  // 云操作命令
    52  	Code        int64       `json:"code"`                 // 云操作状态码
    53  	Description string      `json:"desc"`                 // 与状态码相对应的详细描述
    54  	Error       string      `json:"error,omitempty"`      // 如果处理失败,该字段会给出失败的详细原因
    55  	ErrorIndex  int64       `json:"errorIndex,omitempty"` // 如果处理失败,该字段会给出错误的管道顺序,从0开始,0表示第一段,以此类推。
    56  	Hash        string      `json:"hash"`                 // 云处理结果保存在服务端的唯一标识
    57  	ObjectName  string      `json:"key"`                  // 云处理结果的外链对象名称
    58  	Result      interface{} `json:"result"`               // 当 object_name 和 object_names 都不存在时,此字段会有值,返回 cmd 的处理结果
    59  	ObjectNames ObjectNames `json:"keys,omitempty"`       // 当 cmd 返回多项结果时,此字段会有值,返回云处理结果的外链对象名称列表
    60  	ReturnOld   int64       `json:"returnOld"`            // 是否返回了旧的数据
    61  }
    62  
    63  func (j *PfopTaskItem) MarshalJSON() ([]byte, error) {
    64  	if err := j.validate(); err != nil {
    65  		return nil, err
    66  	}
    67  	return json.Marshal(&jsonPfopTaskItem{Command: j.Command, Code: j.Code, Description: j.Description, Error: j.Error, ErrorIndex: j.ErrorIndex, Hash: j.Hash, ObjectName: j.ObjectName, Result: j.Result, ObjectNames: j.ObjectNames, ReturnOld: j.ReturnOld})
    68  }
    69  
    70  func (j *PfopTaskItem) UnmarshalJSON(data []byte) error {
    71  	var nj jsonPfopTaskItem
    72  	if err := json.Unmarshal(data, &nj); err != nil {
    73  		return err
    74  	}
    75  	j.Command = nj.Command
    76  	j.Code = nj.Code
    77  	j.Description = nj.Description
    78  	j.Error = nj.Error
    79  	j.ErrorIndex = nj.ErrorIndex
    80  	j.Hash = nj.Hash
    81  	j.ObjectName = nj.ObjectName
    82  	j.Result = nj.Result
    83  	j.ObjectNames = nj.ObjectNames
    84  	j.ReturnOld = nj.ReturnOld
    85  	return nil
    86  }
    87  
    88  func (j *PfopTaskItem) validate() error {
    89  	if j.Command == "" {
    90  		return errors.MissingRequiredFieldError{Name: "Command"}
    91  	}
    92  	if j.Code == 0 {
    93  		return errors.MissingRequiredFieldError{Name: "Code"}
    94  	}
    95  	if j.Description == "" {
    96  		return errors.MissingRequiredFieldError{Name: "Description"}
    97  	}
    98  	if j.Hash == "" {
    99  		return errors.MissingRequiredFieldError{Name: "Hash"}
   100  	}
   101  	if j.ObjectName == "" {
   102  		return errors.MissingRequiredFieldError{Name: "ObjectName"}
   103  	}
   104  	if j.Result == nil {
   105  		return errors.MissingRequiredFieldError{Name: "Result"}
   106  	}
   107  	if j.ReturnOld == 0 {
   108  		return errors.MissingRequiredFieldError{Name: "ReturnOld"}
   109  	}
   110  	return nil
   111  }
   112  
   113  // 返回的持久化数据处理任务中的云处理操作列表
   114  type PfopTaskItems = []PfopTaskItem
   115  
   116  // 返回的持久化数据处理任务信息
   117  type (
   118  	PfopTask     = Response
   119  	jsonResponse struct {
   120  		PersistentId string        `json:"id"`                     // 持久化数据处理任务 ID
   121  		Code         int64         `json:"code"`                   // 持久化数据处理任务状态码
   122  		Description  string        `json:"desc"`                   // 与状态码相对应的详细描述
   123  		ObjectName   string        `json:"inputKey"`               // 源对象名称
   124  		BucketName   string        `json:"inputBucket"`            // 源空间名称
   125  		Pipeline     string        `json:"pipeline,omitempty"`     // 云处理操作的处理队列
   126  		TaskFrom     string        `json:"taskFrom,omitempty"`     // 如果没有,则表示通过 `api+fops` 命令提交的任务,否则遵循规则 `<source>: <source_id>`,其中 `<source>` 当前可选 `workflow` 或 `trigger`
   127  		RequestId    string        `json:"reqid"`                  // 云处理请求的请求 ID
   128  		Type         int64         `json:"type,omitempty"`         // 任务类型,支持 `0` 表示普通任务,`1` 表示闲时任务
   129  		CreatedAt    string        `json:"creationDate,omitempty"` // 任务创建时间
   130  		Items        PfopTaskItems `json:"items"`                  // 云处理操作列表
   131  	}
   132  )
   133  
   134  func (j *Response) MarshalJSON() ([]byte, error) {
   135  	if err := j.validate(); err != nil {
   136  		return nil, err
   137  	}
   138  	return json.Marshal(&jsonResponse{PersistentId: j.PersistentId, Code: j.Code, Description: j.Description, ObjectName: j.ObjectName, BucketName: j.BucketName, Pipeline: j.Pipeline, TaskFrom: j.TaskFrom, RequestId: j.RequestId, Type: j.Type, CreatedAt: j.CreatedAt, Items: j.Items})
   139  }
   140  
   141  func (j *Response) UnmarshalJSON(data []byte) error {
   142  	var nj jsonResponse
   143  	if err := json.Unmarshal(data, &nj); err != nil {
   144  		return err
   145  	}
   146  	j.PersistentId = nj.PersistentId
   147  	j.Code = nj.Code
   148  	j.Description = nj.Description
   149  	j.ObjectName = nj.ObjectName
   150  	j.BucketName = nj.BucketName
   151  	j.Pipeline = nj.Pipeline
   152  	j.TaskFrom = nj.TaskFrom
   153  	j.RequestId = nj.RequestId
   154  	j.Type = nj.Type
   155  	j.CreatedAt = nj.CreatedAt
   156  	j.Items = nj.Items
   157  	return nil
   158  }
   159  
   160  func (j *Response) validate() error {
   161  	if j.PersistentId == "" {
   162  		return errors.MissingRequiredFieldError{Name: "PersistentId"}
   163  	}
   164  	if j.Code == 0 {
   165  		return errors.MissingRequiredFieldError{Name: "Code"}
   166  	}
   167  	if j.Description == "" {
   168  		return errors.MissingRequiredFieldError{Name: "Description"}
   169  	}
   170  	if j.ObjectName == "" {
   171  		return errors.MissingRequiredFieldError{Name: "ObjectName"}
   172  	}
   173  	if j.BucketName == "" {
   174  		return errors.MissingRequiredFieldError{Name: "BucketName"}
   175  	}
   176  	if j.RequestId == "" {
   177  		return errors.MissingRequiredFieldError{Name: "RequestId"}
   178  	}
   179  	if len(j.Items) == 0 {
   180  		return errors.MissingRequiredFieldError{Name: "Items"}
   181  	}
   182  	for _, value := range j.Items {
   183  		if err := value.validate(); err != nil {
   184  			return err
   185  		}
   186  	}
   187  	return nil
   188  }