快速使用
在您开始之前,您需要注册阿里云账号并获取您的凭证。下文将以创建一个流程,发起一次执行并获取执行详情为例展示如何使用 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) } }
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。