session

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearSessionCookie

func ClearSessionCookie(w http.ResponseWriter)

ClearSessionCookie removes the session cookie from the response.

func Middleware

func Middleware(store SessionStore) func(http.Handler) http.Handler

Middleware reads the session ID from the cookie, looks up the UserSession from the store, and places it on the request context.

func RequireAuth

func RequireAuth(next http.Handler) http.Handler

RequireAuth redirects unauthenticated requests to /login.

func SetSessionCookie

func SetSessionCookie(w http.ResponseWriter, sessionID string)

SetSessionCookie writes the session cookie to the response.

func WithUserSession

func WithUserSession(ctx context.Context, s *UserSession) context.Context

WithUserSession returns a new context with the UserSession attached.

Types

type MemSessionProvider

type MemSessionProvider struct {
	// contains filtered or unexported fields
}

func NewMemSessionProvider

func NewMemSessionProvider() *MemSessionProvider

func (*MemSessionProvider) Create

func (m *MemSessionProvider) Create(data UserSession) (string, error)

func (*MemSessionProvider) Delete

func (m *MemSessionProvider) Delete(id string) error

func (*MemSessionProvider) DeleteByEmail

func (m *MemSessionProvider) DeleteByEmail(email string) (int, error)

func (*MemSessionProvider) Get

func (m *MemSessionProvider) Get(id string) (*UserSession, error)

func (*MemSessionProvider) ListAll

func (m *MemSessionProvider) ListAll() (map[string]UserSession, error)

func (*MemSessionProvider) Update

func (m *MemSessionProvider) Update(id string, data UserSession) error

type SessionStore

type SessionStore interface {
	Create(data UserSession) (id string, err error)
	Get(id string) (*UserSession, error)
	Update(id string, data UserSession) error
	Delete(id string) error
	DeleteByEmail(email string) (int, error)
	ListAll() (map[string]UserSession, error)
}

type UserSession

type UserSession struct {
	UserId            string    `json:"user_id"`
	Email             string    `json:"email"`
	DisplayName       string    `json:"display_name"`
	ControlPlaneRoles []string  `json:"control_plane_roles"`
	ConsentComplete   bool      `json:"consent_complete"`
	CreatedAt         time.Time `json:"created_at"`
}

func GetUserSession

func GetUserSession(ctx context.Context) *UserSession

GetUserSession returns the UserSession from the context, or nil if not present.

func (*UserSession) IsLoggedIn

func (s *UserSession) IsLoggedIn() bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL