photoprism/internal/event
Michael Mayer 889de682c4 CI: Apply Go linter recommendations to "internal/event" package #5330
Signed-off-by: Michael Mayer <michael@photoprism.app>
2025-11-22 14:10:56 +01:00
..
audit.go Config: Add system warning log when DatabaseDsn is used #5279 2025-10-22 08:16:49 +02:00
buffer.go Logs: Prevent feedback loops by omitting repeated messages #2335 2022-05-20 11:31:39 +02:00
buffer_test.go Logs: Prevent feedback loops by omitting repeated messages #2335 2022-05-20 11:31:39 +02:00
event.go Backend: Update copyright notices 2025-01-09 10:28:17 +01:00
format.go CI: Apply Go linter recommendations to "internal/event" package #5330 2025-11-22 14:10:56 +01:00
format_test.go Logs: Refactor message formatting in event package 2025-03-26 12:58:51 +01:00
hub.go CI: Apply Go linter recommendations to "internal/event" package #5330 2025-11-22 14:10:56 +01:00
hub_test.go Auth: Session and ACL enhancements #98 #1746 2022-09-28 09:01:17 +02:00
init.go Config: Set SystemLog level based on application log level #5167 2025-10-07 21:30:19 +02:00
log.go CI: Apply Go linter recommendations to "internal/event" package #5330 2025-11-22 14:10:56 +01:00
log_test.go Backend: Format go imports 2020-11-21 18:08:41 +01:00
log_writer.go Logging: Add output writer wrapper so the default logger can use Logrus 2022-12-23 01:35:59 +01:00
log_writer_test.go Logging: Add output writer wrapper so the default logger can use Logrus 2022-12-23 01:35:59 +01:00
logger.go Auth: Session and ACL enhancements #98 #1746 2022-09-28 09:01:17 +02:00
login.go Account: Refactor access token API and request forms #808 #4114 2024-04-05 14:46:11 +02:00
publish.go CI: Apply Go linter recommendations to "internal/event" package #5330 2025-11-22 14:10:56 +01:00
publish_entities.go CI: Apply Go linter recommendations to "internal/event" package #5330 2025-11-22 14:10:56 +01:00
publish_entities_test.go Auth: Open album share links in the regular user interface #98 #782 2022-10-02 11:38:30 +02:00
README.md CI: Apply Go linter recommendations to "internal/event" package #5330 2025-11-22 14:10:56 +01:00
system.go Config: Add system warning log when DatabaseDsn is used #5279 2025-10-22 08:16:49 +02:00
system_test.go Security: Add a system log for publishing internal warnings and errors 2025-10-07 21:08:04 +02:00
time.go CI: Apply Go linter recommendations to "internal/event" package #5330 2025-11-22 14:10:56 +01:00

PhotoPrism — Event System

Last Updated: November 22, 2025

Overview

internal/event provides a lightweight pub/sub hub for in-process notifications. It underpins logging hooks, UI notifications, and domain events (entities created/updated/deleted/archived/restored). The package aliases the hub library to keep a stable interface while exposing simple helpers for common topics.

Usage

Publish a custom event:

event.Publish("photos.updated", event.Data{"ids": []string{"p1", "p2"}})

Publish localized notifications:

event.SuccessMsg(i18n.MsgImportDone)
event.Warn("low disk space")

Subscribe to topics:

sub := event.Subscribe("photos.*")
defer event.Unsubscribe(sub)
for msg := range sub.Receiver {
    fmt.Printf("topic=%s payload=%v\n", msg.Name, msg.Fields)
}

Log hook (used by default logger):

hook := event.NewHook(event.SharedHub())
log.AddHook(hook)

Entity events:

event.EntitiesUpdated("photos", updatedPhotos)
event.EntitiesDeleted("files", deletedFiles)

Package Layout (Code Map)

  • Hub aliases & helpers: hub.go, format.go, time.go
  • Logging hook: log.go
  • Publish helpers: publish.go, publish_entities.go
  • Tests: package-level tests alongside sources
  • internal/photoprism — core indexing/import flows that emit events.
  • internal/server — HTTP layer that may consume event notifications.
  • internal/ai/vision & internal/ffmpeg — emit log events via the shared logger.
  • External hub library: github.com/leandro-lugaresi/hub

Testing

  • Lint: golangci-lint run ./internal/event...
  • Unit tests: go test ./internal/event/... (lightweight)

Notes

  • Use SharedHub() for process-wide subscriptions; NewHub() when isolating tests.
  • Topic separator is .; message separator for rendering is .
  • Keep notifications human-readable; payloads should be small to avoid blocking subscribers.