The goal of refactoring was to consolidate session access through CoreData (cd.GetSession()) and minimize direct dependency on core.GetSession() and core.ContextValues("session").
- Added
GetSession()method toCoreDatato satisfygobookmarks.Coreinterface. - Refactored all handlers in
handlers/to usecd.GetSession()instead ofcore.GetSessionOrFail(w, r). - Updated
handlers/matchers.goto prefercd.UserIDwhen available. - Updated unit tests in
handlers/user/to support the refactored code (injectingCoreDatawith session).
internal/middleware/csrf/csrf.go uses core.GetSession(r) directly.
- Reason: The CSRF middleware runs before
CoreDataMiddlewarein the chain, soCoreDatais not yet available in the context. - Action Required: Reorder middleware if possible, or refactor CSRF middleware to be
CoreData-aware (perhaps initializingCoreDataearlier or lazily).
internal/app/server/server.go calls core.GetSession(r) to retrieve the session and then passes it to common.NewCoreData.
- Reason: This is the initialization point.
- Action Required: This usage is likely necessary unless the session retrieval logic is moved entirely inside
NewCoreDataconstructor (which would require passingrandstore).
Many tests still rely on injecting the session directly into the context using core.ContextValues("session").
- Action Required: Update tests to use
handlertest.RequestWithCoreDataor similar helpers that properly encapsulateCoreDatainitialization with session support. - Files:
handlers/forum/*_test.go,handlers/admin/*_test.go, etc. (grep forContextValues("session")).
handlers/matchers.go (RequiresAnAccount) still has a fallback to core.GetSession(request) if CoreData is missing.
- Action Required: Verify if
CoreDatais guaranteed to be present for all routes using this matcher. If so, remove the fallback.
internal/websocket/notifications.go uses core.GetSession(r).
- Reason: Websockets might bypass some middleware or require specific handling.
- Action Required: Investigate if
CoreDatais available in websocket upgrade request context and refactor if possible.