interfaces

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 7 Imported by: 0

README

interfaces package

Purpose: host shared contracts consumed by both the server orchestrator (internal/server) and the handlers package (internal/server/handlers) without creating import cycles. Interfaces in this package should represent cross-cutting dependencies that are injected into handlers.

Current contents:

  • HandlerQueries: read-only gallery queries used by handlers and wired from App via gallerydb generated queries.
  • MetadataQueries: EXIF and IPTC metadata reads consumed by handlers and satisfied by *gallerydb.Queries directly (no adapter).
  • ServerDeps: the primary dependency-injection interface — 24 methods covering credentials, config operations, gallery queries, server control, and template rendering. Implemented by *server.App. Replaces the previous 15+ callback fields and 3 adapter types.
  • StartCacheBatchLoadResult: struct shared by server and handlers for cache batch load outcomes.

Guidelines:

  • Add an interface here only if it is consumed by both server and handlers (or other subpackages) and would otherwise create a dependency loop.
  • Keep handler-only or server-only interfaces close to their packages; avoid growing this directory into a dumping ground.
  • Prefer small, focused interfaces that map to handler needs (e.g., read-only query sets) and can be satisfied by generated query types or mocks.

Future candidates:

  • Login-related persistence (if shared across packages beyond ServerDeps) could be factored into a separate interface here; currently handled via ServerDeps credential methods.

Documentation

Overview

Package interfaces holds shared contracts consumed by both the server orchestrator (App) and the handlers package. These interfaces live here to avoid circular dependencies while keeping the contracts in a neutral, stable location.

Package interfaces holds shared contracts consumed by both the server orchestrator (App) and the handlers package. These interfaces live here to avoid circular dependencies while keeping the contracts in a neutral, stable location.

Package interfaces holds shared contracts consumed by both the server orchestrator (App) and the handlers package. These interfaces live here to avoid circular dependencies while keeping the contracts in a neutral, stable location.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HandlerQueries

type HandlerQueries interface {
	GetFolderViewByID(ctx context.Context, id int64) (gallerydb.FolderView, error)
	GetFoldersViewsByParentIDOrderByName(ctx context.Context, parent sql.NullInt64) ([]gallerydb.FolderView, error)
	GetFileViewsByFolderIDOrderByFileName(ctx context.Context, folderID sql.NullInt64) ([]gallerydb.FileView, error)
	GetFileViewByID(ctx context.Context, id int64) (gallerydb.FileView, error)
	GetFolderByID(ctx context.Context, id int64) (gallerydb.Folder, error)
	GetThumbnailsByFileID(ctx context.Context, fileID int64) (gallerydb.Thumbnail, error)
	GetThumbnailBlobDataByID(ctx context.Context, id int64) ([]byte, error)
	// GetPreloadRoutesByFolderID returns routes to preload for a folder (source of truth: direct children only).
	// Returns *sql.Rows; each row contains a route string to scan.
	GetPreloadRoutesByFolderID(ctx context.Context, parentID sql.NullInt64) (*sql.Rows, error)
	// GetGalleryStatistics returns aggregate statistics about the gallery (folder count, file count, total size, timestamps).
	GetGalleryStatistics(ctx context.Context) (gallerydb.GetGalleryStatisticsRow, error)
}

HandlerQueries abstracts the subset of DB queries used by HTTP handlers. Shared by server and handlers packages.

type MetadataQueries added in v0.8.0

type MetadataQueries interface {
	GetExifByFile(ctx context.Context, fileID int64) (gallerydb.ExifMetadatum, error)
	GetIPTCByFile(ctx context.Context, fileID int64) (gallerydb.IptcMetadatum, error)
}

MetadataQueries abstracts EXIF and IPTC reads for a file. Used by GalleryHandlers (InfoBoxImage).

type ServerDeps added in v0.8.0

type ServerDeps interface {
	// --- Credential operations ---
	CheckAccountLockout(ctx context.Context, username string) (bool, error)
	GetUser(ctx context.Context, username string) (*session.User, error)
	RecordFailedLoginAttempt(ctx context.Context, username string) error
	ClearLoginAttempts(ctx context.Context, username string) error
	UpdateUsername(ctx context.Context, username string) error
	UpdatePassword(ctx context.Context, passwordHash string) error

	// --- Config operations ---
	UpdateConfigWithPrecedence(cfg *config.Config, changedFields []string)
	ApplyConfig()
	InvalidateHTTPCache()
	SetPreloadEnabled(enabled bool)
	SetRestartRequired(b bool)
	TriggerRestart()

	// --- Gallery queries ---
	GetHandlerQueries(cpc *dbconnpool.CpConn) HandlerQueries
	GetMetadataQueries(cpc *dbconnpool.CpConn) MetadataQueries
	GetConfigQueries(cpc *dbconnpool.CpConn) config.ConfigQueries
	GetETagVersion() string
	ImagesDir() string

	// --- Server control ---
	Shutdown()
	TriggerDiscovery()
	ResetStats()
	StartCacheBatchLoad() (StartCacheBatchLoadResult, error)

	// --- Config access ---
	GetConfig() *config.Config

	// --- Template helpers ---
	AddCommonTemplateData(w http.ResponseWriter, r *http.Request, data map[string]any, fullPage bool) map[string]any
	ServerError(w http.ResponseWriter, r *http.Request, err error)
}

ServerDeps provides all server-level dependencies consumed by handler groups. Implemented by *server.App, it replaces the previous callback-field wiring pattern with a single compile-time-checked interface.

type StartCacheBatchLoadResult added in v0.8.0

type StartCacheBatchLoadResult struct {
	Blocked bool   // true if discovery is active
	Message string // toast message
}

StartCacheBatchLoadResult describes the result of attempting to start cache batch load.

Jump to

Keyboard shortcuts

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