We have a basic k6 extension written:
type K6Ext struct{}
func init() {
modules.Register("k6/x/ext", new(K6Ext))
}
type Reader interface {
Foo() error
}
type ReaderImpl struct {}
func (r * ReaderImpl) Foo() error {} // Implementation omitted for brevity
type Stream struct {
reader Reader
}
func (s *K6Ext) XReaderImpl(ctx *context.Context) interface{} {
rt := common.GetRuntime(*ctx)
return common.Bind(rt, &ReaderImpl{}, ctx)
}
func (s *K6Ext) XClient(ctx *context.Context, reader Reader) interface{} {
rt := common.GetRuntime(*ctx)
return common.Bind(rt, &Stream{reader: reader}, ctx)
}
which we try to use in js:
import ext from 'k6/x/ext'
const reader = ext.ReaderImpl()
const stream = ext.Client(reader)
When running this code, it fails with ERRO[0000] GoError: could not convert [object Object] to ext.Reader
I’m not sure if I’m passing this reader
incorrectly here but it feels like I should be able to pass a golang struct to a go method even if the go method argument expects an interface. Any pointers as to how I should properly pass this?