26 lines
603 B
Go
26 lines
603 B
Go
package media
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"sync/atomic"
|
|
)
|
|
|
|
var activeService atomic.Pointer[Service]
|
|
|
|
func setActiveService(service *Service) { activeService.Store(service) }
|
|
func PlaybackRoute(ctx context.Context, id string) (Route, error) {
|
|
service := activeService.Load()
|
|
if service == nil {
|
|
return Route{}, fmt.Errorf("media service is not ready")
|
|
}
|
|
return service.store.Get(ctx, id)
|
|
}
|
|
func PlaybackRoutes(ctx context.Context) ([]Route, error) {
|
|
service := activeService.Load()
|
|
if service == nil {
|
|
return nil, fmt.Errorf("media service is not ready")
|
|
}
|
|
return service.store.List(ctx)
|
|
}
|