47 lines
1 KiB
Text
47 lines
1 KiB
Text
|
|
// Code generated by ndpgen. DO NOT EDIT.
|
||
|
|
//
|
||
|
|
// This file contains client wrappers for the Ping host service.
|
||
|
|
// It is intended for use in Navidrome plugins built with TinyGo.
|
||
|
|
//
|
||
|
|
//go:build wasip1
|
||
|
|
|
||
|
|
package ndhost
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"errors"
|
||
|
|
|
||
|
|
"github.com/navidrome/navidrome/plugins/pdk/go/pdk"
|
||
|
|
)
|
||
|
|
|
||
|
|
// ping_ping is the host function provided by Navidrome.
|
||
|
|
//
|
||
|
|
//go:wasmimport extism:host/user ping_ping
|
||
|
|
func ping_ping(uint64) uint64
|
||
|
|
|
||
|
|
// PingPing calls the ping_ping host function.
|
||
|
|
func PingPing() error {
|
||
|
|
// No parameters - allocate empty JSON object
|
||
|
|
reqMem := pdk.AllocateBytes([]byte("{}"))
|
||
|
|
defer reqMem.Free()
|
||
|
|
|
||
|
|
// Call the host function
|
||
|
|
responsePtr := ping_ping(reqMem.Offset())
|
||
|
|
|
||
|
|
// Read the response from memory
|
||
|
|
responseMem := pdk.FindMemory(responsePtr)
|
||
|
|
responseBytes := responseMem.ReadBytes()
|
||
|
|
|
||
|
|
// Parse error-only response
|
||
|
|
var response struct {
|
||
|
|
Error string `json:"error,omitempty"`
|
||
|
|
}
|
||
|
|
if err := json.Unmarshal(responseBytes, &response); err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
if response.Error != "" {
|
||
|
|
return errors.New(response.Error)
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|