mirror of
https://github.com/navidrome/navidrome.git
synced 2026-02-02 06:24:14 +00:00
74 lines
1.6 KiB
Go
74 lines
1.6 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 ndhost
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
|
|
"github.com/extism/go-pdk"
|
|
)
|
|
|
|
// User represents the User data structure.
|
|
type User struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// Convert Error field to Go error
|
|
if response.Error != "" {
|
|
return nil, errors.New(response.Error)
|
|
}
|
|
|
|
return &response, nil
|
|
}
|