Skip to content

Latest commit

 

History

History
75 lines (54 loc) · 1.89 KB

File metadata and controls

75 lines (54 loc) · 1.89 KB

cmd/web (HTTP Runtime Layer)

This directory is the runtime entrypoint for the bookings monolith.

Responsibilities

  • Application bootstrap (main.go)
  • Runtime wiring (run())
  • HTTP router and route map (routes.go)
  • Middleware stack (middleware.go)
  • Mail listener/SMTP send worker (send-mail.go)

Startup Flow

  1. main() calls run().
  2. run():
  • registers session-serializable types with gob
  • reads runtime flags
  • configures logs and SCS session manager
  • connects to PostgreSQL
  • builds template cache
  • wires repository into handlers
  • wires renderer/helpers with app config
  1. main() starts mail listener goroutine.
  2. HTTP server starts on :8080 with routes(&app).

Middleware Chain

Configured in this order:

  1. Recoverer (Chi)
  2. NoSurf (global CSRF protection)
  3. SessionLoad (load/save session per request)

Admin routes add:

  • Auth middleware, requiring user_id in session.

Route Groups

Public pages

  • /, /about, /contact
  • /generals-quarters, /majors-suite
  • /search-availability (GET/POST)
  • /search-availability-json (POST)
  • /choose-room/{id}, /book-room
  • /make-reservation (GET/POST)
  • /reservation-summary

Auth

  • /user/login (GET/POST)
  • /user/logout

Admin (/admin/*, protected)

  • dashboard
  • new/all reservations lists
  • reservation show/edit
  • reservation process/delete actions
  • reservation calendar and block management

Mail Worker

  • A goroutine continuously reads app.MailChan.
  • Messages are sent via local SMTP (localhost:1025) using go-simple-mail.
  • If Template is set, email body is rendered from email-templates/<template> and injected with content.

Flags and Operational Notes

  • -db-name and -db-user are required.
  • -cache controls template-cache usage.
  • -production toggles secure cookies and related runtime behavior.
  • Build script example exists in project root run.sh.