Documentation
¶
Overview ¶
Package server provides the core HTTP server, routing, middleware, and handlers for the web application. This file holds route registration.
Package server provides the core HTTP server, routing, middleware, and handlers for the web application. It integrates all the sub-packages like database, caching, and background workers to serve the photo gallery.
Index ¶
- Constants
- func MakeAuthCookie(t *testing.T, app *App) *http.Cookie
- type App
- func CreateApp(t *testing.T, startPool bool) *App
- func CreateAppWithOpt(tb testing.TB, startPool bool, opt getopt.Opt) *App
- func CreateAppWithRoot(t *testing.T, startPool bool, rootDir string) *App
- func CreateAppWithRootAndOpt(t *testing.T, startPool bool, rootDir string, opt getopt.Opt) *App
- func CreateAppWithTB(tb testing.TB, startPool bool) *App
- func New(opt getopt.Opt, version string) *App
- func (app *App) GetETagVersion() string
- func (app *App) IncrementETag() (string, error)
- func (app *App) InitForIncrementETag(opt getopt.Opt) error
- func (app *App) InitForUnlock() error
- func (app *App) LogProfileLocation()
- func (app *App) RestartRequired() bool
- func (app *App) RestartServer(server *http.Server) error
- func (app *App) Run(minPoolWorkers, maxPoolWorkers int) error
- func (app *App) Serve() error
- func (app *App) Shutdown()
- func (app *App) UnlockAccount(username string) error
- type BatchedWrite
- type Config
- type ConfigDiff
- type ConfigQueries
- type ConfigSaver
- type GalleryStats
- type MemoryReclaimerConfig
Constants ¶
const (
// SQLiteDriverName is the name of the SQLite driver to use
SQLiteDriverName = "sqlite3"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type App ¶
type App struct {
// ImporterFactory allows tests or callers to override how Importer instances are constructed.
ImporterFactory func(conn *sql.Conn, q *gallerydb.CustomQueries) files.Importer
// contains filtered or unexported fields
}
App holds the shared state and resources for the entire application. It manages database connections, worker pools, queues, caching, application context, and a task scheduler for recurring and one-time tasks.
Lock Ordering: To prevent deadlocks, always acquire locks in this order when holding multiple locks: 1. ctxMu 2. configMu 3. restartMu Never acquire a lower-ordered lock while holding a higher-ordered one.
func CreateAppWithOpt ¶
CreateAppWithOpt sets up a full, isolated application instance for testing with custom options. It creates and wires services in order: ConfigService (setDB), FileProcessor, session/store/restartCh (ensureSessionAndRestart), Handlers (buildHandlers). All services are non-nil when CreateApp returns.
func CreateAppWithRoot ¶
CreateAppWithRoot sets up a full application instance using an existing root directory. Useful for simulating restarts while preserving the same database.
func CreateAppWithRootAndOpt ¶
CreateAppWithRootAndOpt sets up a full application instance using an existing root directory and options.
func CreateAppWithTB ¶
CreateAppWithTB sets up a full, isolated application instance for benchmarks or tests. Use CreateApp for regular tests; use CreateAppWithTB(b, false) in benchmarks.
func New ¶
New creates and initializes a new App instance. It sets up the application context, session secret, importer factory, and other core components.
func (*App) GetETagVersion ¶
GetETagVersion returns the current ETag version for cache-busting URLs. Thread-safe: acquires configMu.RLock to read app.config.ETagVersion.
func (*App) IncrementETag ¶
IncrementETag loads current ETag, increments it, saves to database, and returns new value.
func (*App) InitForIncrementETag ¶
InitForIncrementETag initializes minimal app state for --increment-etag command. Similar to InitForUnlock, this sets up only what's needed for ETag operations.
func (*App) InitForUnlock ¶
InitForUnlock performs minimal initialization needed for unlock operations. It sets up root directory and database using the database package. This is a minimal initialization that does not require config to be loaded.
func (*App) LogProfileLocation ¶
func (app *App) LogProfileLocation()
LogProfileLocation logs the profile directory and stops the profiler if active. This should be called before shutdown to ensure profile location is logged to both console and file.
func (*App) RestartRequired ¶
RestartRequired returns true if a server restart is required due to configuration changes that require restart.
func (*App) RestartServer ¶
RestartServer gracefully shuts down the HTTP server and restarts it. If only listener settings (address/port) changed, it performs an HTTP-only restart. Otherwise, it performs a full restart.
func (*App) Run ¶
Run orchestrates the application startup sequence. It initializes the root directory, logging, database, configuration, and command-line parsing. It then starts the background worker pool and file discovery process before starting the HTTP server.
func (*App) Serve ¶
Serve initializes the session store and starts the HTTP server on the configured port. It supports graceful restart via the restart channel.
func (*App) Shutdown ¶
func (app *App) Shutdown()
Shutdown gracefully shuts down the application. It cancels the main context, waits for background goroutines and the worker pool to finish, closes database connections, and closes the log file.
func (*App) UnlockAccount ¶
UnlockAccount unlocks a locked account by clearing failed attempts and removing the lockout.
type BatchedWrite ¶
type BatchedWrite struct {
File *files.File // File metadata + EXIF + thumbnails
InvalidFile *gallerydb.UpsertInvalidFileParams // Invalid file tracking
CacheEntry *cachelite.HTTPCacheEntry // HTTP cache entries
}
BatchedWrite is a union type for all high-volume database writes. Exactly one field should be non-nil per instance.
func (BatchedWrite) Size ¶
func (bw BatchedWrite) Size() int64
Size returns estimated memory cost in bytes for batch size limiting.
type Config ¶
Config is the main application configuration type. It is defined in the config package and re-exported here for backward compatibility.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a Config with all default values.
type ConfigDiff ¶
type ConfigDiff = config.ConfigDiff
ConfigDiff is an alias for config.ConfigDiff to maintain backward compatibility.
type ConfigQueries ¶
type ConfigQueries = config.ConfigQueries
ConfigQueries is an alias for config.ConfigQueries to maintain backward compatibility.
type ConfigSaver ¶
type ConfigSaver = config.ConfigSaver
ConfigSaver is an alias for config.ConfigSaver to maintain backward compatibility.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package auth provides authentication services for the application.
|
Package auth provides authentication services for the application. |
|
Package cachepreload provides cache preloading when folders are opened.
|
Package cachepreload provides cache preloading when folders are opened. |
|
Package compress provides pure functions for content encoding negotiation and compression decision making.
|
Package compress provides pure functions for content encoding negotiation and compression decision making. |
|
Package conditional provides pure functions for HTTP conditional request matching.
|
Package conditional provides pure functions for HTTP conditional request matching. |
|
Package files provides file discovery, metadata extraction, and thumbnail generation for the photo gallery.
|
Package files provides file discovery, metadata extraction, and thumbnail generation for the photo gallery. |
|
Package handlers provides HTTP request handlers for the web application.
|
Package handlers provides HTTP request handlers for the web application. |
|
Package interfaces holds shared contracts consumed by both the server orchestrator (App) and the handlers package.
|
Package interfaces holds shared contracts consumed by both the server orchestrator (App) and the handlers package. |
|
Package metrics provides centralized metrics collection for the dashboard.
|
Package metrics provides centralized metrics collection for the dashboard. |
|
Package pathutil provides path manipulation utilities for the server package.
|
Package pathutil provides path manipulation utilities for the server package. |
|
Package restart provides pure functions for determining server restart requirements.
|
Package restart provides pure functions for determining server restart requirements. |
|
Package security provides pure functions for security and lockout calculations.
|
Package security provides pure functions for security and lockout calculations. |
|
Package session provides session store, CSRF token handling, and session cookie options for the web application.
|
Package session provides session store, CSRF token handling, and session cookie options for the web application. |
|
Package template provides pure functions for building template data maps.
|
Package template provides pure functions for building template data maps. |
|
Package ui provides HTML template rendering and cache version management for the application's user interface.
|
Package ui provides HTML template rendering and cache version management for the application's user interface. |