我只是在尝试一些基本的 Uber Cadence 示例。我遇到如下问题:我有一个活动,它接收一个结构作为参数并更改值并返回修改后的结构。执行时我无法获得修改后的值工作流。它显示默认值。我尝试如下代码片段:
type Product struct {
vendor string // "Arrows"
productCategory string // "Clothing"
productName string // "Shirt"
description string // "Shirt for Gents"
size int // 42
cost float32// 2.00
color string // "Red"
auctionOption string // "Buy it Now"
}
// populateProduct
func newProduct() *Product {
p := Product{vendor: "Arrows"}
p.productCategory = "Clothing"
p.productName = "Shirt"
p.description = "Shirt for Gents"
p.size = 42
p.cost = 2.00
p.color = "Red"
p.auctionOption = "Buy it Now"
return &p
}
// Activity
func NewProductActivity(ctx context.Context) (*Product, error) {
logger := activity.GetLogger(ctx)
logger.Info("NewProductActivity started.................")
np := newProduct()
return np, nil
}
// Workflow
func MarketPlaceWorkflow(ctx workflow.Context, name string) (string, error) {
ctx = workflow.WithActivityOptions(ctx, activityOptions)
logger := workflow.GetLogger(ctx)
logger.Info("MarketPlace workflow started!................")
// Invoking NewProductActivity
var npActivityResult Product
err := workflow.ExecuteActivity(ctx, NewProductActivity).Get(ctx, &npActivityResult)
if err != nil {
logger.Error("MarketPlace workflow NewProductActivity failed!.............", zap.Error(err))
return "", err
}
logger.Info("Vendor: ", zap.String("Vendor", npActivityResult.vendor)) // It is showing default values
return "", nil
}