oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1package docs
2
3import (
4 "context"
5 "database/sql"
6 "log/slog"
7 "net/http"
8
9 "amadan.net/rastrillo/rastrillo/sessions"
10)
11
12// Keep validation in the shared reader: FromContext bounds the session
13// lookup by the caller's context. (Before Docs moved off rastrillo's
14// pre-move path, this converted between the two packages' Session types.)
15func newTeamSessionReader(db *sql.DB, origin, cookieName string, logger *slog.Logger) (func(context.Context, *http.Request) (sessions.Session, bool), error) {
16 reader, e := sessions.New(sessions.Config{DB: db, Origin: origin, Logger: logger})
17 if e != nil || reader.CookieName() != cookieName {
18 return nil, errTeamConfig
19 }
20 return func(ctx context.Context, r *http.Request) (sessions.Session, bool) {
21 if _, present, ok := homeCookie(r, cookieName); !ok || !present {
22 return sessions.Session{}, false
23 }
24 return reader.FromContext(ctx, r)
25 }, nil
26}
27