猿问

为什么不从 Cadence 活动传递私有成员?

我注意到,当我使用由公共成员和私有成员组成的结构时,私有成员不会被 Cadence 活动复制(?)。


例如我有一个结构:


package foo


type Foo struct {

    Name        string

    PublicList  []string

    privateList []string

}


func NewFoo() *Foo {

    return &Foo{

        Name:        "Test",

        PublicList:  []string{"A", "B", "C"},

        privateList: []string{"one", "two"},

    }

}


func (f *Foo) ShowLists() {

    fmt.Println("PublicList: ", f.PublicList, ", privateList: ", f.privateList)

}


我还使用其他结构,注册为活动结构:


package activities 


type FooActivities struct{}


func (a *FooActivities) NewFoo(ctx context.Context) (*foo.Foo, error) {

    return foo.NewFoo(), nil

}


func (a *FooActivities) ShowLists(ctx context.Context, f *foo.Foo) error {

    f.ShowLists()

    return nil

}


我的工作流程按以下方式调用这两个活动:


var f *foo.Foo

workflow.ExecuteActivity(ctx, fooActivities.NewFoo).Get(ctx, &f)

workflow.ExecuteActivity(ctx, fooActivities.ShowLists, f).Get(ctx, nil)

结果,按ShowLists功能打印:


公共列表:[ABC],私人列表:[]


为什么私有列表没有按预期初始化?这是错误还是功能?我在 Cadence 文档中找不到这个问题的答案。


至尊宝的传说
浏览 127回答 2
2回答

郎朗坤

Cadence(和 Temporal)默认用于json.Marshal序列化和json.Unmarshall反序列化活动参数。它不会序列化私有字段。这是一个可能的解决方法。

慕桂英4014372

我认为这是因为 reflect can't copy unexported field
随时随地看视频慕课网APP

相关分类

Go
我要回答