Hi,
I got this error when doing this
“err”:“payload item 0: value type: interface {}: must be a concrete type, not interface”
func Activity(ctx context.Context, input interface{}) interface{} {return something}
var result interface{}
workflow.ExecuteActivity(ctx, Activity, input).Get(ctx, result)
am i missing something?
Yes, you cannot unmarshal to an empty interface using the default converters because the default converters use the type to know how to unmarshal. There is no “default” type for the data using default converters like there is with json. You can however supply your own data converter which could unmarshal from a raw payload to interface{}
.
Thanks for the reply, do you have an example for the customized converter? is it an interface provided by temporal sdk?
alex
October 21, 2021, 6:39pm
8
func Activity(ctx context.Context, input interface{}) interface{} {return something}
What is something
here? I guess it is some proto message. Because with plain string
, this works fine (modified helloworld example):
func Activity(ctx context.Context, name string) (interface{}, error) {
return "Hello " + name + "!", nil
}
func Workflow(ctx workflow.Context, name string) (interface{}, error) {
//...
var result interface{}
err := workflow.ExecuteActivity(ctx, Activity, name).Get(ctx, &result)
//...
return result, nil
}
we, err := c.ExecuteWorkflow(context.Background(), workflowOptions, helloworld.Workflow, "Temporal")
var result interface{}
err = we.Get(context.Background(), &result)
yes, the something is a proto msg
alex
October 27, 2021, 8:19pm
10
So there is no way to unmarshal proto message to interface{}
. You should use plain go struct there or specify exact type when unmarshal.
In case of plain go struct you will get map[string]interface{}
in you variable of interface{}
type. It is built-in json.Unmarshal
underneath.