60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
|
|
// Code generated by ndpgen. DO NOT EDIT.
|
||
|
|
//
|
||
|
|
// This file contains export wrappers for the Lifecycle capability.
|
||
|
|
// It is intended for use in Navidrome plugins built with TinyGo.
|
||
|
|
//
|
||
|
|
//go:build wasip1
|
||
|
|
|
||
|
|
package lifecycle
|
||
|
|
|
||
|
|
import (
|
||
|
|
"github.com/navidrome/navidrome/plugins/pdk/go/pdk"
|
||
|
|
)
|
||
|
|
|
||
|
|
// Lifecycle is the marker interface for lifecycle plugins.
|
||
|
|
// Implement one or more of the provider interfaces below.
|
||
|
|
// Lifecycle provides plugin lifecycle hooks.
|
||
|
|
// This capability allows plugins to perform initialization when loaded,
|
||
|
|
// such as establishing connections, starting background processes, or
|
||
|
|
// validating configuration.
|
||
|
|
//
|
||
|
|
// The OnInit function is called once when the plugin is loaded, and is NOT
|
||
|
|
// called when the plugin is hot-reloaded. Plugins should not assume this
|
||
|
|
// function will be called on every startup.
|
||
|
|
type Lifecycle interface{}
|
||
|
|
|
||
|
|
// InitProvider provides the OnInit function.
|
||
|
|
type InitProvider interface {
|
||
|
|
OnInit() error
|
||
|
|
} // Internal implementation holders
|
||
|
|
var (
|
||
|
|
initImpl func() error
|
||
|
|
)
|
||
|
|
|
||
|
|
// Register registers a lifecycle implementation.
|
||
|
|
// The implementation is checked for optional provider interfaces.
|
||
|
|
func Register(impl Lifecycle) {
|
||
|
|
if p, ok := impl.(InitProvider); ok {
|
||
|
|
initImpl = p.OnInit
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// NotImplementedCode is the standard return code for unimplemented functions.
|
||
|
|
// The host recognizes this and skips the plugin gracefully.
|
||
|
|
const NotImplementedCode int32 = -2
|
||
|
|
|
||
|
|
//go:wasmexport nd_on_init
|
||
|
|
func _NdOnInit() int32 {
|
||
|
|
if initImpl == nil {
|
||
|
|
// Return standard code - host will skip this plugin gracefully
|
||
|
|
return NotImplementedCode
|
||
|
|
}
|
||
|
|
|
||
|
|
if err := initImpl(); err != nil {
|
||
|
|
pdk.SetError(err)
|
||
|
|
return -1
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0
|
||
|
|
}
|