Documentation
¶
Overview ¶
Package api owns the HTTP surface of the server: REST endpoints, the media file server and the WebSocket event stream.
Index ¶
- Constants
- type Server
- func (s *Server) Close() error
- func (s *Server) Handler() http.Handler
- func (s *Server) Run(ctx context.Context) error
- func (s *Server) Serve(ctx context.Context, listener net.Listener) error
- func (s *Server) StartPrefetch(ctx context.Context)
- func (s *Server) TrimMedia(ctx context.Context, progress func(done, total int)) (int, int, error)
Constants ¶
const ProviderTimeout = 15 * time.Second
ProviderTimeout bounds each provider's share of a fan-out search.
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.
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 ¶
New builds the server: it opens the store and instantiates the enabled providers and the media pipeline.
func (*Server) Handler ¶
Handler exposes the fully wrapped HTTP handler (rate limits, auth, routes).
func (*Server) Serve ¶
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 ¶
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.
Source Files
¶
- account.go
- archives.go
- artwork.go
- auth.go
- collections.go
- duplicates.go
- favorites.go
- friends.go
- history.go
- imports.go
- jobs.go
- library.go
- lyrics.go
- media.go
- middleware.go
- openapi.go
- playback.go
- playlists.go
- playlists_search.go
- prefetch.go
- providers.go
- radio.go
- ranking.go
- ratelimit.go
- respond.go
- rooms.go
- search.go
- searchanswers.go
- server.go
- sources.go
- tracks.go
- uploads.go
- ws.go