Add an in-process post event bus (#13)
CI / test (push) Successful in 6m16s

Handlers emit PostCreated and PostUpdated after a successful write. Store writes do not publish, and hidden roots are skipped.

Reviewed-on: #13
Co-authored-by: codegirl-007 <s.raide@gmail.com>
This commit was merged in pull request #13.
This commit is contained in:
2026-08-29 18:24:13 +00:00
committed by codegirl007
parent 19fea892f3
commit 911355ae35
10 changed files with 600 additions and 2 deletions
+7
View File
@@ -20,6 +20,7 @@ import (
"github.com/go-chi/chi/v5/middleware"
"plumber/internal/blob"
"plumber/internal/events"
"plumber/internal/geo"
"plumber/internal/mail"
"plumber/internal/pacific"
@@ -35,6 +36,8 @@ type Config struct {
TrustedProxies []*net.IPNet
Blob blob.Uploader
Mail mail.Notifier
Events events.Publisher
BaseURL string
}
type Server struct {
@@ -110,6 +113,9 @@ func New(st store.Store, sessionStore scs.Store, templateFS fs.FS, staticFS fs.F
if cfg.Mail == nil {
cfg.Mail = mail.Nop{}
}
if cfg.Events == nil {
cfg.Events = events.Nop{}
}
funcMap := template.FuncMap{
"voteCtx": func(user *store.User, csrf, view, date string, post *store.Post) voteCtx {
return voteCtx{User: user, CSRF: csrf, View: view, Date: date, Post: post}
@@ -371,6 +377,7 @@ func (s *Server) handleSubmit(w http.ResponseWriter, r *http.Request) {
http.Error(w, "could not save question", http.StatusInternalServerError)
return
}
s.publishPostCreated(post, post, u)
http.Redirect(w, r, "/questions/"+url.PathEscape(post.ID), http.StatusSeeOther)
}