navidrome/plugins/cmd/hostgen/testdata/store_client_expected.go
Deluan 06e6c09882 refactor: error handling in various plugins to convert response.Error to Go errors
- Updated error handling in `nd_host_scheduler.go`, `nd_host_websocket.go`, `nd_host_artwork.go`, `nd_host_cache.go`, and `nd_host_subsonicapi.go` to convert string errors from responses into Go errors.
- Removed redundant error checks in test data plugins for cleaner code.
- Ensured consistent error handling across all plugins to improve reliability and maintainability.
2025-12-31 17:06:29 -05:00

66 lines
1.4 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"
"errors"
"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
// StoreSaveRequest is the request type for Store.Save.
type StoreSaveRequest struct {
Item Item `json:"item"`
}
// 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) {
// Marshal request to JSON
req := StoreSaveRequest{
Item: item,
}
reqBytes, err := json.Marshal(req)
if err != nil {
return nil, err
}
reqMem := pdk.AllocateBytes(reqBytes)
defer reqMem.Free()
// Call the host function
responsePtr := store_save(reqMem.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
}
// Convert Error field to Go error
if response.Error != "" {
return nil, errors.New(response.Error)
}
return &response, nil
}