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) InitForBatchLoad(opt getopt.Opt) 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) Run(minPoolWorkers, maxPoolWorkers int) error
- func (app *App) RunCacheBatchLoad() int
- func (app *App) Serve() error
- func (app *App) Shutdown()
- func (app *App) UnlockAccount(username string) error
- type BatchedWrite
- type Configdeprecated
- func DefaultConfig() *Configdeprecated
- type ConfigDiffdeprecated
- type ConfigQueriesdeprecated
- type ConfigSaverdeprecated
- 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 {
// 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) InitForBatchLoad ¶ added in v0.3.0
InitForBatchLoad performs minimal initialization for cache batch load CLI. Sets root dir, opens DB pools, loads config, initializes HTTP cache, builds handler chain. No server start, no discovery, no worker pool.
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 ¶
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 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. The actual restart is triggered via the restart channel (restartCh) in server.go's event loop, not through this package.
func (*App) RunCacheBatchLoad ¶ added in v0.3.0
RunCacheBatchLoad runs the batch load and returns the exit code: 0 success, 1 error, 2 blocked.
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 drains the WriteBatcher first, then 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
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) GobDecode ¶ added in v0.3.0
func (bw *BatchedWrite) GobDecode(data []byte) error
GobDecode deserializes BatchedWrite from the gob-safe wire format, reconstructing the files.File (including its Thumbnail) and cache entry from their separately-encoded blobs.
func (BatchedWrite) GobEncode ¶ added in v0.3.0
func (bw BatchedWrite) GobEncode() ([]byte, error)
GobEncode serializes BatchedWrite into a gob-safe wire format. Since files.File now has its own GobEncode/GobDecode handling the *bytes.Buffer Thumbnail, we can encode it directly without copying or mutating the caller's object.
func (BatchedWrite) Size ¶
func (bw BatchedWrite) Size() int64
Size returns estimated memory cost in bytes for batch size limiting.
type Config
deprecated
Deprecated: Config is a type alias for config.Config. Use config.Config directly in new code.
func DefaultConfig
deprecated
func DefaultConfig() *Config
Deprecated: DefaultConfig returns a Config with all default values. Use config.DefaultConfig directly in new code.
type ConfigDiff
deprecated
type ConfigDiff = config.ConfigDiff
Deprecated: ConfigDiff is a type alias for config.ConfigDiff. Use config.ConfigDiff directly in new code.
type ConfigQueries
deprecated
type ConfigQueries = config.ConfigQueries
Deprecated: ConfigQueries is a type alias for config.ConfigQueries. Use config.ConfigQueries directly in new code.
type ConfigSaver
deprecated
type ConfigSaver = config.ConfigSaver
Deprecated: ConfigSaver is a type alias for config.ConfigSaver. Use config.ConfigSaver directly in new code.
Source Files
¶
- app.go
- app_auth.go
- app_cache.go
- app_config.go
- app_db.go
- app_handler_deps.go
- app_infra.go
- app_runtime.go
- app_startup.go
- app_subsystems.go
- batched_write.go
- batched_write_flush.go
- batcher_adapter.go
- cache_submit.go
- config.go
- config_test_helpers.go
- handler_queries.go
- metrics_adapters.go
- profiler_log.go
- restart.go
- router.go
- server.go
- test_helpers.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package auth provides authentication services for the application.
|
Package auth provides authentication services for the application. |
|
Package cachebatch provides batch cache loading with bounded concurrency.
|
Package cachebatch provides batch cache loading with bounded concurrency. |
|
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 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. |