// 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 }