navidrome/plugins/cmd/hostgen/testdata/ping_expected.go
Deluan a0a5168f5f fix(generator): error-only methods in response handling
Signed-off-by: Deluan <deluan@navidrome.org>
2025-12-31 17:06:28 -05:00

42 lines
1.0 KiB
Go

// Code generated by hostgen. DO NOT EDIT.
package testpkg
import (
"context"
extism "github.com/extism/go-sdk"
)
// RegisterPingHostFunctions registers Ping service host functions.
// The returned host functions should be added to the plugin's configuration.
func RegisterPingHostFunctions(service PingService) []extism.HostFunction {
return []extism.HostFunction{
newPingPingHostFunction(service),
}
}
func newPingPingHostFunction(service PingService) extism.HostFunction {
return extism.NewHostFunctionWithStack(
"ping_ping",
func(ctx context.Context, p *extism.CurrentPlugin, stack []uint64) {
// Call the service method
err := service.Ping(ctx)
if err != nil {
// Write error string to plugin memory
if ptr, err := p.WriteString(err.Error()); err == nil {
stack[0] = ptr
}
return
}
// Write empty string to indicate success
if ptr, err := p.WriteString(""); err == nil {
stack[0] = ptr
}
},
[]extism.ValueType{},
[]extism.ValueType{extism.ValueTypePTR},
)
}