api

package
v0.0.0-...-d2e4998 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: GPL-2.0 Imports: 45 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api owns the HTTP surface of the server: REST endpoints, the media file server and the WebSocket event stream.

Index

Constants

View Source
const ProviderTimeout = 15 * time.Second

ProviderTimeout bounds each provider's share of a fan-out search.

View Source
const SearchAnswerTTL = 45 * time.Second

searchAnswers holds the last few answers to the same question, and makes sure a question is only put to the providers once at a time.

Two things come out of that, and both are the point:

  • speed. A search is a provider round trip - for the music services this server talks to, a whole process and a page fetch - and a person typing asks the same question several times over (every prefix, back and forth over a letter, one tab after another). Within the window the answer is already here.
  • consistency. Providers order their hits by whatever they like, and the list moves between two identical asks: the same query shows the songs in a different order a second later. Held for the window, the answer to one question is one answer.

Sharing an in-flight ask matters as much as the cache: the tracks tab and the albums tab asking at once, or two people asking the same thing, cost one provider call rather than one each - and every one of those is a process. SearchAnswerTTL is how long an answer is kept. Long enough that typing the same words again - every prefix, back and forth over a letter, one tab after another - costs nothing and shows the same list; short enough that a re-asked question still reaches the providers.

View Source
const ShutdownTimeout = 10 * time.Second

ShutdownTimeout bounds graceful shutdown after the context is cancelled.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the HTTP server. Everything the daemon does is reachable through it; the CLI and any bot are plain API clients.

func New

func New(cfg *config.Config, logger *slog.Logger) (*Server, error)

New builds the server: it opens the store and instantiates the enabled providers and the media pipeline.

func (*Server) Close

func (s *Server) Close() error

Close releases the server's resources.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler exposes the fully wrapped HTTP handler (rate limits, auth, routes).

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run serves on the configured listen address until ctx is cancelled.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, listener net.Listener) error

Serve serves HTTP on listener until ctx is cancelled, then shuts down gracefully. It is the single place the server serves from, so every caller gets the same middleware stack.

func (*Server) StartPrefetch

func (s *Server) StartPrefetch(ctx context.Context)

StartPrefetch begins the background playlist prefetch. Run starts it for a serving daemon; an embedder that serves the handler itself - the CLI's in-process server - must call it too, or media.prefetchPlaylists quietly does nothing.

func (*Server) TrimMedia

func (s *Server) TrimMedia(ctx context.Context, progress func(done, total int)) (int, int, error)

TrimMedia walks the library and takes the silence off the renditions that end in some, so the stored length of a song is the length of the music. It is a maintenance pass, not part of serving, and it is safe to run again.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL