ERRO[0000] TypeError: Object has no member 'PrintString'

Unable to properly import and access go functions, running log in go file to see if it is registering, module is confirmed registered

package xk6_decodeProto

import (
	"go.finxact.io/engineering/services/protobuf/model-go/v1/observability/entities"
	"go.k6.io/k6/js/modules"
	"log"
	//"go/finxact.io/engineering/services/protobus/model-go/v1/observability/entities"
)

// Register the extension as a k6 module
func init() {
	log.Println("Registering xk6-decodeProto module")
	modules.Register("k6/x/binarydecoder", new(BinaryDecoder))
	log.Println("xk6-decodeProto module registered")
}

// Define the BinaryDecoder struct, which implements the k6 module
type BinaryDecoder struct{}

// decodeBinary decodes binary data into a map (similar to a JS object)
func (b *BinaryDecoder) DecodeBinary(data []byte) map[string]interface{} {
	newRequest := entities.MessageLogRequest{}

	// Unmarshal the binary data into the `newRequest` struct
	err := newRequest.UnmarshalVT(data)
	if err != nil {
		log.Println("Failed to decode binary:", err)
		return nil
	}

	// Map the fields from newRequest to a map for JavaScript
	result := map[string]interface{}{
		"ID":            newRequest.GetId(),
		"Body":          newRequest.GetBody(),
		"URL":           newRequest.GetUrl(),
		"Method":        newRequest.GetMethod(),
		"RemoteAddress": newRequest.GetIpAddress(),
		"Params":        newRequest.GetParams(),
		"TenantID":      newRequest.GetTenantId(),
	}

	return result
}

// Expose the DecodeBinary function to JavaScript
func (b *BinaryDecoder) DecodeBinaryJS(data []byte) map[string]interface{} {
	result := b.DecodeBinary(data)
	if result == nil {
		panic("Failed to decode binary data")
	}
	return result
}

// PrintString is a simple utility to demonstrate exposing a function to JS
func (b *BinaryDecoder) PrintString(word string) {

	log.Println("PrintString called with word:", word)
}

`1. * List item`

//import  individual classes and consultants
import {Writer, Reader, Connection, SchemaRegistry, SCHEMA_TYPE_STRING} from "k6/x/kafka";
import {client, closeClient, connectClient, requestData, responseData} from "./functionalTests.js";
import grpc from 'k6/net/grpc';
import {check,fail} from 'k6';
import * as binaryDecoder from 'k6/x/binarydecoder';
// import {MessageLogRequest} from "./message-log-request.pb";
// import "../../../../model-proto/schema/v1/observability/apis/shared-observability-messagelog-api.proto"

// instantiate classes in the init context
// Creates a new Writer object to produce messages to Kafka

const writer = new Writer({
    // WriterConfig object
    brokers: ["localhost:9092"],
    topic: "34.v1.observability.entities.message_log_request",
});

const reader = new Reader({
    // ReaderConfig object
    brokers: ["localhost:9092"],
    topic: "34.v1.observability.entities.message_log_request",
});

//kafka connection
const connection = new Connection({
    // ConnectionConfig object
    address: "localhost:9092",
});



//virtual users, test params
export const options = {
    vus: 1,
    duration: '15s',
    iterations: 1,

};




// load model
client.load(['../../../../model-proto/schema'],'v1/observability/apis/shared-observability-messagelog-api.proto');




const schemaRegistry = new SchemaRegistry();
// Can accept a SchemaRegistryConfig object


export default function () {

    connectClient();

    const request = requestData();

    const response = responseData();


    check(request, {
        'request status is OK': (r) => r && r.status === grpc.StatusOK,
    });

    check(response, {
        'response status is OK': (r) => r && r.status === grpc.StatusOK,
    });

    console.log(`Check request: Expected empty response` +"'"+ JSON.stringify(request.message)+"'");
    console.log(`Check response: Expected empty response` +"'"+JSON.stringify(response.message)+"'");



    // closeClient();

    // Fetch the list of all topics
    // const topics = connection.listTopics();
    // console.log(topics); // list of topics

    // Consume messages from Kafka
    const messages = reader.consume({ limit: 1, nanoPrecision: false,expectTimeout: true});


    // You can use checks to verify the contents,
    // length and other properties of the message(s)

    // To serialize the data back into a string, you should use
    // the deserialize method of the Schema Registry client. You
    // can use it inside a check, as shown in the example scripts.

    // let decode = MessageLogRequest.decode(messages[0].value)
    let deserializedValue = schemaRegistry.deserialize({
        data: messages[0].value,
        schemaType: SCHEMA_TYPE_STRING});

    // let error = produce(producer, messages);
    // check(error, {
    //     "is sent": (err) => err == undefined,
    // });
    check(deserializedValue, {
        'message is not empty': (msg) => msg !== "",
    });
    const binaryData = new Uint8Array(messages[0].value);
    // const word = binarydecoder.PrintString("it works")
    // const result = binarydecoder.BinaryDecoder.DecodeBinaryJS(messages[0].value);
    // console.log(JSON.stringify(result));
    // console.log(binaryData)
    // console.log(deserializedValue)
    console.log(binaryDecoder.PrintString("loser"))


}

export function teardown(data) {


    // Close all connections
    closeClient()
    writer.close();
    reader.close();
    connection.close();
}

Hi.

This forum is about Grafana plugin development. Perhaps opening an issue in the k6 project will help you better with this question GitHub - grafana/k6: A modern load testing tool, using Go and JavaScript - https://k6.io