navidrome/plugins/cmd/hostgen/testdata/users_client_expected.go
Deluan cab656dbe5 refactor: host function wrappers to use structured request and response types
- Updated the host function signatures in `nd_host_artwork.go`, `nd_host_scheduler.go`, `nd_host_subsonicapi.go`, and `nd_host_websocket.go` to accept a single parameter for JSON requests.
- Introduced structured request and response types for various cache operations in `nd_host_cache.go`.
- Modified cache functions to marshal requests to JSON and unmarshal responses, improving error handling and code clarity.
- Removed redundant memory allocation for string parameters in favor of JSON marshaling.
- Enhanced error handling in WebSocket and cache operations to return structured error responses.
2025-12-31 17:06:29 -05:00

62 lines
1.4 KiB
Go

// Code generated by hostgen. DO NOT EDIT.
//
// This file contains client wrappers for the Users 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"
)
// users_get is the host function provided by Navidrome.
//
//go:wasmimport extism:host/user users_get
func users_get(uint64) uint64
// UsersGetRequest is the request type for Users.Get.
type UsersGetRequest struct {
Id *string `json:"id"`
Filter *User `json:"filter"`
}
// UsersGetResponse is the response type for Users.Get.
type UsersGetResponse struct {
Result *User `json:"result,omitempty"`
Error string `json:"error,omitempty"`
}
// UsersGet calls the users_get host function.
func UsersGet(id *string, filter *User) (*UsersGetResponse, error) {
// Marshal request to JSON
req := UsersGetRequest{
Id: id,
Filter: filter,
}
reqBytes, err := json.Marshal(req)
if err != nil {
return nil, err
}
reqMem := pdk.AllocateBytes(reqBytes)
defer reqMem.Free()
// Call the host function
responsePtr := users_get(reqMem.Offset())
// Read the response from memory
responseMem := pdk.FindMemory(responsePtr)
responseBytes := responseMem.ReadBytes()
// Parse the response
var response UsersGetResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return nil, err
}
return &response, nil
}