mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-21 00:37:09 +02:00
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
|
|
// Code generated by ndpgen. DO NOT EDIT.
|
||
|
|
|
||
|
|
package host
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"encoding/json"
|
||
|
|
|
||
|
|
extism "github.com/extism/go-sdk"
|
||
|
|
)
|
||
|
|
|
||
|
|
// StorageGetStoragePathResponse is the response type for Storage.GetStoragePath.
|
||
|
|
type StorageGetStoragePathResponse struct {
|
||
|
|
Result string `json:"result,omitempty"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// RegisterStorageHostFunctions registers Storage service host functions.
|
||
|
|
// The returned host functions should be added to the plugin's configuration.
|
||
|
|
func RegisterStorageHostFunctions(service StorageService) []extism.HostFunction {
|
||
|
|
return []extism.HostFunction{
|
||
|
|
newStorageGetStoragePathHostFunction(service),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func newStorageGetStoragePathHostFunction(service StorageService) extism.HostFunction {
|
||
|
|
return extism.NewHostFunctionWithStack(
|
||
|
|
"storage_getstoragepath",
|
||
|
|
func(ctx context.Context, p *extism.CurrentPlugin, stack []uint64) {
|
||
|
|
|
||
|
|
// Call the service method
|
||
|
|
result := service.GetStoragePath(ctx)
|
||
|
|
|
||
|
|
// Write JSON response to plugin memory
|
||
|
|
resp := StorageGetStoragePathResponse{
|
||
|
|
Result: result,
|
||
|
|
}
|
||
|
|
storageWriteResponse(p, stack, resp)
|
||
|
|
},
|
||
|
|
[]extism.ValueType{extism.ValueTypePTR},
|
||
|
|
[]extism.ValueType{extism.ValueTypePTR},
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
// storageWriteResponse writes a JSON response to plugin memory.
|
||
|
|
func storageWriteResponse(p *extism.CurrentPlugin, stack []uint64, resp any) {
|
||
|
|
respBytes, err := json.Marshal(resp)
|
||
|
|
if err != nil {
|
||
|
|
storageWriteError(p, stack, err)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
respPtr, err := p.WriteBytes(respBytes)
|
||
|
|
if err != nil {
|
||
|
|
stack[0] = 0
|
||
|
|
return
|
||
|
|
}
|
||
|
|
stack[0] = respPtr
|
||
|
|
}
|
||
|
|
|
||
|
|
// storageWriteError writes an error response to plugin memory.
|
||
|
|
func storageWriteError(p *extism.CurrentPlugin, stack []uint64, err error) {
|
||
|
|
errResp := struct {
|
||
|
|
Error string `json:"error"`
|
||
|
|
}{Error: err.Error()}
|
||
|
|
respBytes, _ := json.Marshal(errResp)
|
||
|
|
respPtr, _ := p.WriteBytes(respBytes)
|
||
|
|
stack[0] = respPtr
|
||
|
|
}
|