数据工坊 DWR-自定义函数开发规范:对接截图函数示例(GO语言)

时间:2025-02-12 14:54:13

对接截图函数示例(GO语言)

 1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
package mainimport ("encoding/json""errors""go-runtime/go-api/context")func DemoHandler(jsonData []byte, ctx context.RuntimeContext) (interface{}, error) {var eventMsg Payloaderr := json.Unmarshal(jsonData, &eventMsg)if err != nil {return nil, errors.New("not correct format")}// 存储输入桶和对象值record := eventMsg.Records[0]// 定义输出resp := struct {OBSMessagesInputs        map[string]interface{} `json:"inputs"`ExecutionName string                 `json:"execution_name"`GraphName     string                 `json:"graph_name"`DynamicSource struct {*CreateThumbnailDynamicSourceBody} `json:"dynamic_source"`}{}// 配置截图参数,为下游截图任务提供参数配置resp.DynamicSource.CreateThumbnailDynamicSourceBody = &CreateThumbnailDynamicSourceBody{Thumbnails: []*ThumbnailCreateTaskBody{&ThumbnailCreateTaskBody{//源文件地址。Input: &FileAddr{Location:   "cn-north-1",BucketName: record.Obs.Bucket.Name,Object:     record.Obs.Object.Key,},//输出地址。Output: &FileAddr{Location:   "cn-north-1",BucketName: record.Obs.Bucket.Name,Object:     "thumb_out",},//是否压缩抽帧图片生成tar包。Tar: 0,//是否同步处理,同步处理是指不下载全部文件,快速定位到截图位置进行截图。Mode: 0,//截图参数ThumbnailParam: &ThumbnailParam{Type:           "DOTS",MaxLength:      0,Dots:           []int64{2, 10, 14}, // 截图的位置(s)OutputFileName: "default_cover.jpg",},},},}// 以下参数需要继承传递,方便工作流下游函数获取对应参数值resp.Inputs = eventMsg.Inputsresp.Records = eventMsg.Recordsresp.GraphName = eventMsg.GraphNameresp.ExecutionName = eventMsg.ExecutionNamereturn resp, nil}
support.huaweicloud.com/usermanual-dwr/dwr_03_0008.html