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

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

对接转码函数示例(GO语言)

 1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
package mainimport ("encoding/json""errors""go-runtime/go-api/context")func DemoTranscodeHandler(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 {*CreateTranscodeDynamicSourceBody} `json:"dynamic_source"`}{}// 配置截图参数,为下游截图任务提供参数配置resp.DynamicSource.CreateTranscodeDynamicSourceBody = &CreateTranscodeDynamicSourceBody{Transcodes: []*CreateTranscodeTaskBody{&CreateTranscodeTaskBody{//源文件地址。Input: &FileAddr{Location:   "cn-north-4",BucketName: record.Obs.Bucket.Name,Object:     record.Obs.Object.Key,},//输出地址。Output: &FileAddr{Location:   "cn-north-4",BucketName: record.Obs.Bucket.Name,Object:     "transcode_out",},TransTemplateID: []int{7000523, 7000524, 7000526, 7000528, 7000530, 7000538},OutputFilenames: []string{"out_file1", "out_file2", "out_file3", "out_file4", "out_file5", "out_file6"},},},}// 以下参数需要继承传递,方便工作流下游函数获取对应参数值resp.Inputs = eventMsg.Inputsresp.Records = eventMsg.Recordsresp.GraphName = eventMsg.GraphNameresp.ExecutionName = eventMsg.ExecutionNamereturn resp, nil}
support.huaweicloud.com/usermanual-dwr/dwr_03_0008.html