mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-18 07:30:29 +00:00
Navidrome Host Function Wrappers for Go
This directory contains auto-generated Go wrappers for Navidrome's host services. These wrappers provide idiomatic Go APIs for interacting with Navidrome from WASM plugins.
⚠️ Auto-Generated Code
Do not edit these files manually. They are generated by the hostgen tool.
To regenerate:
cd plugins/host
go generate
Usage
Add this module as a dependency in your plugin's go.mod:
require github.com/navidrome/navidrome/plugins/host/go v0.0.0
replace github.com/navidrome/navidrome/plugins/host/go => ../../host/go
Then import the package in your plugin code:
package main
import (
ndhost "github.com/navidrome/navidrome/plugins/host/go"
"github.com/extism/go-pdk"
)
func myPluginFunction() error {
// Use the cache service
_, err := ndhost.CacheSetString("my_key", "my_value", 3600)
if err != nil {
return err
}
// Schedule a recurring task
_, err = ndhost.SchedulerScheduleRecurring("@every 5m", "payload", "task_id")
if err != nil {
return err
}
// Access library data with typed structs
resp, err := ndhost.LibraryGetAllLibraries()
if err != nil {
return err
}
for _, lib := range resp.Result {
pdk.Log(pdk.LogInfo, fmt.Sprintf("Library: %s with %d songs", lib.Name, lib.TotalSongs))
}
return nil
}
Typed Structs
Services that work with domain objects provide typed Go structs instead of
map[string]interface{}. This enables compile-time type checking and IDE
autocompletion.
For example, the library service provides a Library struct:
resp, err := ndhost.LibraryGetAllLibraries()
if err != nil {
return err
}
for _, lib := range resp.Result {
fmt.Printf("Library: %s (%d songs)\n", lib.Name, lib.TotalSongs)
}
Available Services
| Module | Description |
|---|---|
Artwork |
Access album and artist artwork |
Cache |
Temporary key-value storage with TTL |
KVStore |
Persistent key-value storage |
Library |
Access the music library (albums, artists, tracks) |
Scheduler |
Schedule one-time and recurring tasks |
SubsonicAPI |
Make Subsonic API calls |
WebSocket |
Send real-time messages to clients |
Building Plugins
Go plugins must be compiled to WebAssembly using TinyGo:
tinygo build -o plugin.wasm -target=wasip1 -buildmode=c-shared .
See the discord-rich-presence example for a complete plugin implementation.