navidrome/plugins/cmd/hostgen/testdata/store_client_expected.go
2025-12-31 17:06:29 -05:00

51 lines
1.2 KiB
Go

// Code generated by hostgen. DO NOT EDIT.
//
// This file contains client wrappers for the Store host service.
// It is intended for use in Navidrome plugins built with TinyGo.
//
//go:build wasip1
package main
import (
"encoding/json"
"github.com/extism/go-pdk"
)
// store_save is the host function provided by Navidrome.
//
//go:wasmimport extism:host/user store_save
func store_save(uint64) uint64
// StoreSaveResponse is the response type for Store.Save.
type StoreSaveResponse struct {
Id string `json:"id,omitempty"`
Error string `json:"error,omitempty"`
}
// StoreSave calls the store_save host function.
func StoreSave(item Item) (*StoreSaveResponse, error) {
itemBytes, err := json.Marshal(item)
if err != nil {
return nil, err
}
itemMem := pdk.AllocateBytes(itemBytes)
defer itemMem.Free()
// Call the host function
responsePtr := store_save(itemMem.Offset())
// Read the response from memory
responseMem := pdk.FindMemory(responsePtr)
responseBytes := responseMem.ReadBytes()
// Parse the response
var response StoreSaveResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return nil, err
}
return &response, nil
}