This repository has been archived on 2022-08-26. You can view files and clone it, but cannot push or open issues or pull requests.
gosocial/pkg/middleware/session.go

21 lines
431 B
Go
Raw Normal View History

package middleware
import (
"context"
"net/http"
"git.kirsle.net/apps/gosocial/pkg/session"
)
// Session middleware.
func Session(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Check for the session_id cookie.
sess := session.LoadOrNew(r)
ctx := context.WithValue(r.Context(), session.ContextKey, sess)
handler.ServeHTTP(w, r.WithContext(ctx))
})
}