mirror of
https://github.com/navidrome/navidrome.git
synced 2026-02-02 06:24:14 +00:00
66 lines
1.5 KiB
Go
66 lines
1.5 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.
|
|
//
|
|
//go:build wasip1
|
|
|
|
package ndhost
|
|
|
|
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
|
|
|
|
// EchoEchoRequest is the request type for Echo.Echo.
|
|
type EchoEchoRequest struct {
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
// 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) {
|
|
// Marshal request to JSON
|
|
req := EchoEchoRequest{
|
|
Message: message,
|
|
}
|
|
reqBytes, err := json.Marshal(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
reqMem := pdk.AllocateBytes(reqBytes)
|
|
defer reqMem.Free()
|
|
|
|
// Call the host function
|
|
responsePtr := echo_echo(reqMem.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
|
|
}
|
|
|
|
// Convert Error field to Go error
|
|
if response.Error != "" {
|
|
return nil, errors.New(response.Error)
|
|
}
|
|
|
|
return &response, nil
|
|
}
|