interfaces

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 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 ConfigOps added in v0.9.0

type ConfigOps interface {
	UpdateConfigWithPrecedence(cfg *config.Config, changedFields []string)
	ApplyConfig()
	InvalidateHTTPCache()
	SetPreloadEnabled(enabled bool)
	SetRestartRequired(b bool)
	TriggerRestart()
}

ConfigOps provides configuration update operations for applying config changes, managing restart flags, and invalidating caches. Extracted as a narrow interface from ServerDeps.

type CredentialStore added in v0.9.0

type CredentialStore interface {
	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
}

CredentialStore provides credential-related operations for authentication and user management. Extracted as a narrow interface from ServerDeps.

type GalleryOps added in v0.9.0

type GalleryOps interface {
	GetHandlerQueries(cpc *dbconnpool.CpConn) HandlerQueries
	GetMetadataQueries(cpc *dbconnpool.CpConn) MetadataQueries
	GetConfigQueries(cpc *dbconnpool.CpConn) config.ConfigQueries
	GetETagVersion() string
	ImagesDir() string
}

GalleryOps provides gallery query operations — handler queries, metadata, config queries, ETag versioning, and the images directory path. Extracted as a narrow interface from ServerDeps.

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)
	GetFileFolderIndexByID(ctx context.Context, id int64) (gallerydb.GetFileFolderIndexByIDRow, error)
	GetLightboxNavByFileID(ctx context.Context, id int64) (gallerydb.GetLightboxNavByFileIDRow, error)
	GetFolderInfoCountsByID(ctx context.Context, id int64) (gallerydb.GetFolderInfoCountsByIDRow, error)
	GetGalleryFileThumbRowsByFolderID(ctx context.Context, folderID sql.NullInt64) ([]gallerydb.GetGalleryFileThumbRowsByFolderIDRow, error)
	GetGalleryFolderThumbRowsByParentID(ctx context.Context, parentID sql.NullInt64) ([]gallerydb.GetGalleryFolderThumbRowsByParentIDRow, 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 ServerControl added in v0.9.0

type ServerControl interface {
	Shutdown()
	TriggerDiscovery(ctx context.Context) error
	ResetStats()
	StartCacheBatchLoad() (StartCacheBatchLoadResult, error)
	// ManualDiscoveryError returns the in-memory error from a manual
	// POST /server/discovery rebuild failure, or "" when none. Cleared on
	// restart.
	ManualDiscoveryError() string
	// SetManualDiscoveryError sets or clears the manual discovery rebuild
	// error. An empty msg clears it (acknowledged by the operator).
	SetManualDiscoveryError(msg string)
}

ServerControl provides server lifecycle operations — shutdown, discovery, stats reset, and cache batch loading. Extracted as a narrow interface from ServerDeps.

type ServerDeps added in v0.8.0

type ServerDeps interface {
	CredentialStore
	ConfigOps
	GalleryOps
	ServerControl

	// --- 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.

CredentialStore, ConfigOps, GalleryOps, and ServerControl are embedded for backward compatibility — handler groups that need only narrow interfaces can accept them directly instead of the full ServerDeps.

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