navidrome/plugins/cmd/hostgen/testdata/echo_client_expected.go
Deluan ba27a8ceef feat(plugins): generate client wrappers for host functions
Signed-off-by: Deluan <deluan@navidrome.org>
2025-12-31 17:06:28 -05:00

50 lines
1.1 KiB
Go

// Code generated by hostgen. DO NOT EDIT.
//
// This file contains client wrappers for the Echo host service.
// It is intended for use in Navidrome plugins built with TinyGo.
package main
import (
"encoding/json"
"errors"
"github.com/extism/go-pdk"
)
// echo_echo is the host function provided by Navidrome.
//
//go:wasmimport extism:host/user echo_echo
func echo_echo(uint64) uint64
// EchoEchoResponse is the response type for Echo.Echo.
type EchoEchoResponse struct {
Reply string `json:"reply,omitempty"`
Error string `json:"error,omitempty"`
}
// EchoEcho calls the echo_echo host function.
func EchoEcho(message string) (*EchoEchoResponse, error) {
messageMem := pdk.AllocateString(message)
defer messageMem.Free()
// Call the host function
responsePtr := echo_echo(messageMem.Offset())
// Read the response from memory
responseMem := pdk.FindMemory(responsePtr)
responseBytes := responseMem.ReadBytes()
// Parse the response
var response EchoEchoResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return nil, err
}
if response.Error != "" {
return nil, errors.New(response.Error)
}
return &response, nil
}