开发者社区 > 云原生 > Serverless > 正文

有Serverless 工作流的Go SDK 使用示例吗?

有Serverless 工作流的Go SDK 使用示例吗?

展开
收起
小天使爱美 2020-03-27 10:44:34 787 0
1 条回答
写回答
取消 提交回答
  • 快速使用

    在您开始之前,您需要注册阿里云账号并获取您的凭证。下文将以创建一个流程,发起一次执行并获取执行详情为例展示如何使用 Go SDK 调用 Serverless 工作流服务。

    请求方式

    package main

    import ( "fmt" "time"

    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/fnf"
    

    )

    var ( flowDefinitionType = "FDL" flowName = "xxx" flowDefinition = xxx flowDescription = "some descriptions" roleArn = "acs:ram::${Your_Account_ID}:${Your_Role}" executionName = "xxx" )

    // CreateFlow ... func CreateFlow(cli *fnf.Client) (*fnf.CreateFlowResponse, error) { request := fnf.CreateCreateFlowRequest() request.Name = flowName request.Definition = flowDefinition request.Description = flowDescription request.Type = flowDefinitionType request.RoleArn = roleArn return cli.CreateFlow(request) }

    // StartExecution ... func StartExecution(cli *fnf.Client) (*fnf.StartExecutionResponse, error) { request := fnf.CreateStartExecutionRequest() request.FlowName = flowName request.ExecutionName = executionName return cli.StartExecution(request) }

    // DescribeExecution ... func DescribeExecution(cli *fnf.Client) (*fnf.DescribeExecutionResponse, error) { request := fnf.CreateDescribeExecutionRequest() request.FlowName = flowName request.ExecutionName = executionName return cli.DescribeExecution(request) }

    // GetExecutionHistory ... func GetExecutionHistory(cli *fnf.Client) (*fnf.GetExecutionHistoryResponse, error) { request := fnf.CreateGetExecutionHistoryRequest() // request.Limit and request.NextToken can set here. For easy demo, we passed. request.FlowName = flowName request.ExecutionName = executionName return cli.GetExecutionHistory(request) }

    创建客户端并利用上述函数发起一系列调用 说明 如果您需要不加改造进行调试的话,请将下述函数与上述请求方式代码块置于同一个文件中,避免在 import 时报错。

    func main() { fnfCli, err := fnf.NewClientWithAccessKey("cn-hangzhou", "AccessID", "AccessKey") if err != nil { panic(err) } // Create a flow _, err = CreateFlow(fnfCli) if err != nil { panic(err) } // StartExecution _, err = StartExecution(fnfCli) if err != nil { panic(err) } time.Sleep(time.Second) // DescribeExecution desResp, err := DescribeExecution(fnfCli) if err != nil { panic(err) } fmt.Println(fmt.Sprintf("%s status: %s", desResp.Name, desResp.Status)) // GetExecutionHistory _, err = GetExecutionHistory(fnfCli) if err != nil { panic(err) } }

    2020-04-15 23:07:05
    赞同 展开评论 打赏

快速交付实现商业价值。

相关产品

  • 函数计算
  • 热门讨论

    热门文章

    相关电子书

    更多
    Hologres Serverless之路:揭秘弹性计算组 立即下载
    Serverless开发平台: 让研发效能再提升 立即下载
    Serverless 引领云上研发新范式 立即下载