mirror of
https://github.com/navidrome/navidrome.git
synced 2026-05-03 06:51:16 +00:00
docs: update README to reflect changes in plugin import paths
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
451475a7af
commit
8d586f7425
@ -330,23 +330,23 @@ func ndSchedulerCallback() int32 {
|
|||||||
Add the generated SDK to your `go.mod`:
|
Add the generated SDK to your `go.mod`:
|
||||||
|
|
||||||
```
|
```
|
||||||
require github.com/navidrome/navidrome/plugins/host/go v0.0.0
|
require github.com/navidrome/navidrome/plugins/pdk/go v0.0.0
|
||||||
replace github.com/navidrome/navidrome/plugins/host/go => ../../host/go
|
replace github.com/navidrome/navidrome/plugins/pdk/go => ../../pdk/go
|
||||||
```
|
```
|
||||||
|
|
||||||
Then import and use:
|
Then import and use:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import ndhost "github.com/navidrome/navidrome/plugins/host/go"
|
import "github.com/navidrome/navidrome/plugins/pdk/go/host"
|
||||||
|
|
||||||
// Schedule one-time task in 60 seconds
|
// Schedule one-time task in 60 seconds
|
||||||
scheduleID, err := ndhost.SchedulerScheduleOneTime(60, "my-payload", "")
|
scheduleID, err := host.SchedulerScheduleOneTime(60, "my-payload", "")
|
||||||
|
|
||||||
// Schedule recurring task with cron expression (every hour)
|
// Schedule recurring task with cron expression (every hour)
|
||||||
scheduleID, err := ndhost.SchedulerScheduleRecurring("0 * * * *", "hourly-task", "")
|
scheduleID, err := host.SchedulerScheduleRecurring("0 * * * *", "hourly-task", "")
|
||||||
|
|
||||||
// Cancel a task
|
// Cancel a task
|
||||||
err := ndhost.SchedulerCancelSchedule(scheduleID)
|
err := host.SchedulerCancelSchedule(scheduleID)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Cache
|
### Cache
|
||||||
@ -387,13 +387,13 @@ Store and retrieve data in an in-memory TTL-based cache. Each plugin has its own
|
|||||||
Import the Go SDK (see [Scheduler](#scheduler) for `go.mod` setup):
|
Import the Go SDK (see [Scheduler](#scheduler) for `go.mod` setup):
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import ndhost "github.com/navidrome/navidrome/plugins/host/go"
|
import "github.com/navidrome/navidrome/plugins/pdk/go/host"
|
||||||
|
|
||||||
// Cache a value for 1 hour
|
// Cache a value for 1 hour
|
||||||
ndhost.CacheSetString("api-response", responseData, 3600)
|
host.CacheSetString("api-response", responseData, 3600)
|
||||||
|
|
||||||
// Retrieve (check Exists before using Value)
|
// Retrieve (check Exists before using Value)
|
||||||
result, err := ndhost.CacheGetString("api-response")
|
result, err := host.CacheGetString("api-response")
|
||||||
if result.Exists {
|
if result.Exists {
|
||||||
data := result.Value
|
data := result.Value
|
||||||
}
|
}
|
||||||
@ -441,31 +441,31 @@ Persistent key-value storage that survives server restarts. Each plugin has its
|
|||||||
Import the Go SDK (see [Scheduler](#scheduler) for `go.mod` setup):
|
Import the Go SDK (see [Scheduler](#scheduler) for `go.mod` setup):
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import ndhost "github.com/navidrome/navidrome/plugins/host/go"
|
import "github.com/navidrome/navidrome/plugins/pdk/go/host"
|
||||||
|
|
||||||
// Store a value (as raw bytes)
|
// Store a value (as raw bytes)
|
||||||
token := []byte(`{"access_token": "xyz", "refresh_token": "abc"}`)
|
token := []byte(`{"access_token": "xyz", "refresh_token": "abc"}`)
|
||||||
_, err := ndhost.KVStoreSet("oauth:spotify", token)
|
_, err := host.KVStoreSet("oauth:spotify", token)
|
||||||
|
|
||||||
// Retrieve a value
|
// Retrieve a value
|
||||||
result, err := ndhost.KVStoreGet("oauth:spotify")
|
result, err := host.KVStoreGet("oauth:spotify")
|
||||||
if result.Exists {
|
if result.Exists {
|
||||||
var tokenData map[string]string
|
var tokenData map[string]string
|
||||||
json.Unmarshal(result.Value, &tokenData)
|
json.Unmarshal(result.Value, &tokenData)
|
||||||
}
|
}
|
||||||
|
|
||||||
// List all keys with prefix
|
// List all keys with prefix
|
||||||
keysResult, err := ndhost.KVStoreList("user:")
|
keysResult, err := host.KVStoreList("user:")
|
||||||
for _, key := range keysResult.Keys {
|
for _, key := range keysResult.Keys {
|
||||||
// Process each key
|
// Process each key
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check storage usage
|
// Check storage usage
|
||||||
usageResult, err := KVStoreGetStorageUsed()
|
usageResult, err := host.KVStoreGetStorageUsed()
|
||||||
fmt.Printf("Using %d bytes\n", usageResult.Bytes)
|
fmt.Printf("Using %d bytes\n", usageResult.Bytes)
|
||||||
|
|
||||||
// Delete a value
|
// Delete a value
|
||||||
KVStoreDelete("oauth:spotify")
|
host.KVStoreDelete("oauth:spotify")
|
||||||
```
|
```
|
||||||
|
|
||||||
> **Note:** Unlike Cache, KVStore data persists across server restarts. Storage is located at `${DataFolder}/plugins/${pluginID}/kvstore.db`.
|
> **Note:** Unlike Cache, KVStore data persists across server restarts. Storage is located at `${DataFolder}/plugins/${pluginID}/kvstore.db`.
|
||||||
@ -571,19 +571,19 @@ entries, err := os.ReadDir("/libraries/1/Artist")
|
|||||||
Import the Go SDK (see [Scheduler](#scheduler) for `go.mod` setup). The `Library` struct is provided by the SDK:
|
Import the Go SDK (see [Scheduler](#scheduler) for `go.mod` setup). The `Library` struct is provided by the SDK:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import ndhost "github.com/navidrome/navidrome/plugins/host/go"
|
import "github.com/navidrome/navidrome/plugins/pdk/go/host"
|
||||||
|
|
||||||
// Get a specific library
|
// Get a specific library
|
||||||
resp, err := ndhost.LibraryGetLibrary(1)
|
resp, err := host.LibraryGetLibrary(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Handle error
|
// Handle error
|
||||||
}
|
}
|
||||||
library := resp.Result
|
library := resp.Result
|
||||||
|
|
||||||
// Get all libraries
|
// Get all libraries
|
||||||
resp, err := ndhost.LibraryGetAllLibraries()
|
resp, err := host.LibraryGetAllLibraries()
|
||||||
for _, lib := range resp.Result {
|
for _, lib := range resp.Result {
|
||||||
// lib is of type ndhost.Library
|
// lib is of type host.Library
|
||||||
fmt.Printf("Library: %s (%d songs)\n", lib.Name, lib.TotalSongs)
|
fmt.Printf("Library: %s (%d songs)\n", lib.Name, lib.TotalSongs)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -847,7 +847,7 @@ Generated SDKs for calling host services are in `plugins/pdk/go/`, `plugins/pdk/
|
|||||||
**For Go plugins:** Import the SDK as a Go module:
|
**For Go plugins:** Import the SDK as a Go module:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import ndhost "github.com/navidrome/navidrome/plugins/pdk/go/host"
|
import "github.com/navidrome/navidrome/plugins/pdk/go/host"
|
||||||
```
|
```
|
||||||
|
|
||||||
Add to your `go.mod`:
|
Add to your `go.mod`:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user