server

package
v0.0.0-...-17c6387 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewOpenAPI

func NewOpenAPI() *huma.OpenAPI

Types

type EmbedConfig

type EmbedConfig struct {
	Theme *ThemeConfig `json:"theme,omitempty"`
	UI    *UIConfig    `json:"ui,omitempty"`
}

type Event

type Event struct {
	Type string
	Data any
}

Event represents an SSE event to broadcast.

type EventHub

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

EventHub manages SSE subscribers with fan-out broadcasting.

func NewEventHub

func NewEventHub() *EventHub

NewEventHub creates a ready-to-use hub.

func (*EventHub) Broadcast

func (h *EventHub) Broadcast(event Event)

Broadcast sends an event to all subscribers. If event.Type is "sync_status", the event is cached for future subscribers. Slow consumers (full channel) are evicted.

func (*EventHub) Close

func (h *EventHub) Close()

Close shuts down the hub: closes the done channel so SSE handlers exit, marks the hub closed so future Subscribe calls fail fast, then cleans up all subscriber channels.

func (*EventHub) Subscribe

func (h *EventHub) Subscribe(ctx context.Context) (<-chan Event, <-chan struct{})

Subscribe registers a new subscriber. Returns the event channel and the hub's done channel. The event channel is pre-loaded with the cached lastSyncStatus if available. If the hub is already closed, returns an immediately-closed channel and the closed done channel so callers can exit cleanly without leaking a goroutine.

type RepoRef

type RepoRef struct {
	Owner string `json:"owner"`
	Name  string `json:"name"`
}

type Server

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

Server holds the HTTP mux and its dependencies.

func New

func New(
	database *db.DB,
	syncer *ghclient.Syncer,
	frontend fs.FS,
	basePath string,
	cfg *config.Config,
	opts ServerOptions,
) *Server

New creates a Server without config persistence. Pass cfg for repo filtering (can be nil for tests that don't need filtering).

func NewWithConfig

func NewWithConfig(
	database *db.DB,
	syncer *ghclient.Syncer,
	clones *gitclone.Manager,
	frontend fs.FS,
	cfg *config.Config,
	cfgPath string,
	opts ServerOptions,
) *Server

NewWithConfig creates a Server with config persistence for settings/repo endpoints.

func (*Server) ActiveWorktreeKey

func (s *Server) ActiveWorktreeKey() (string, bool)

ActiveWorktreeKey returns the key of the currently focused worktree and whether it was explicitly set. Thread-safe.

func (*Server) Hub

func (s *Server) Hub() *EventHub

Hub returns the server's SSE event hub. Callers should never retain the returned pointer beyond the server's lifetime.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

ListenAndServe starts the HTTP server on addr. Returns http.ErrServerClosed when stopped by Shutdown (matches net/http).

func (*Server) Serve

func (s *Server) Serve(ln net.Listener) error

Serve accepts HTTP connections on the provided listener. Useful for tests and any caller that wants to own the listener lifetime. Returns http.ErrServerClosed when stopped by Shutdown.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler so Server can be used directly.

func (*Server) SetActiveWorktreeKey

func (s *Server) SetActiveWorktreeKey(key string)

SetActiveWorktreeKey sets the key of the currently focused worktree. Thread-safe.

func (*Server) SetVersion

func (s *Server) SetVersion(v string)

SetVersion sets the version string returned by GET /api/v1/version.

func (*Server) Shutdown

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

Shutdown stops the HTTP listener (if started via ListenAndServe or Serve), closes the SSE event hub so streaming handlers exit, cancels background goroutines' context, and blocks until they finish or ctx expires. Safe to call concurrently and repeatedly. Every caller drives http.Server.Shutdown with its own ctx (stdlib polls idle-conn closure per call) and waits on a shared drain channel, so a retry with a longer deadline observes true drain for both HTTP handlers and the bg group. Only the first caller closes the hub and cancels bgCtx.

type ServerOptions

type ServerOptions struct {
	EmbedConfig *EmbedConfig
	Clones      *gitclone.Manager // optional clone manager for diff view
}

type ThemeConfig

type ThemeConfig struct {
	Mode   string            `json:"mode,omitempty"`
	Colors map[string]string `json:"colors,omitempty"`
	Fonts  map[string]string `json:"fonts,omitempty"`
	Radii  map[string]string `json:"radii,omitempty"`
}

type UIConfig

type UIConfig struct {
	HideSync          *bool    `json:"hideSync,omitempty"`
	HideRepoSelector  *bool    `json:"hideRepoSelector,omitempty"`
	HideStar          *bool    `json:"hideStar,omitempty"`
	SidebarCollapsed  *bool    `json:"sidebarCollapsed,omitempty"`
	Repo              *RepoRef `json:"repo,omitempty"`
	ActiveWorktreeKey string   `json:"activeWorktreeKey,omitempty"`
}

Jump to

Keyboard shortcuts

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