internal/event/README.md
Last Updated: November 22, 2025
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.
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)
hub.go, format.go, time.golog.gopublish.go, publish_entities.gointernal/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.github.com/leandro-lugaresi/hubgolangci-lint run ./internal/event...go test ./internal/event/... (lightweight)SharedHub() for process-wide subscriptions; NewHub() when isolating tests..; message separator for rendering is ›.