http

package
v0.0.0-...-e11dccf Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUserFromContext

func GetUserFromContext(ctx context.Context) *model.User

GetUserFromContext, which may be nil if the user is not authenticated.

func Login

func Login(r *Router, page html.PageFunc, log *snorkel.Logger, db loginner, sp sessionPutter)

func Logout

func Logout(r *Router, page html.PageFunc, log *snorkel.Logger, sd sessionDestroyer)

Logout creates an http.Handler for logging out. It just destroys the current user session.

func NotFound

func NotFound(page html.PageFunc) http.HandlerFunc

func RedirectIfAuthenticated

func RedirectIfAuthenticated(h http.Handler) http.Handler

func RedirectIfNotAuthenticated

func RedirectIfNotAuthenticated(h http.Handler) http.Handler

func Signup

func Signup(r *Router, page html.PageFunc, log *snorkel.Logger, db signupper)

func Static

func Static(mux chi.Router)

Types

type Middleware

type Middleware = func(http.Handler) http.Handler

func Authenticate

func Authenticate(redirect bool, sg sessionGetter, db userGetter, log *snorkel.Logger) Middleware

Authenticate checks that there's a user logged in, and otherwise either: - redirects to the login page, - or calls the next handler depending on the passed parameter.

type NewServerOptions

type NewServerOptions struct {
	Address            string
	AdminPassword      string
	BaseURL            string
	HTMLPage           html.PageFunc
	HTTPRouterInjector func(*Router)
	LLMClient          *llm.OpenAIClient
	Log                *snorkel.Logger
	SecureCookie       bool
	SQLHelper          *sql.Helper
}

type Router

type Router struct {
	Mux chi.Router
}

func (*Router) Get

func (r *Router) Get(path string, cb func(props html.PageProps) (Node, error))

func (*Router) Group

func (r *Router) Group(cb func(r *Router))

func (*Router) NotFound

func (r *Router) NotFound(h http.HandlerFunc)

func (*Router) Post

func (r *Router) Post(path string, cb func(props html.PageProps) (Node, error))

func (*Router) Route

func (r *Router) Route(pattern string, cb func(r *Router))

func (*Router) Use

func (r *Router) Use(middleware func(http.Handler) http.Handler)

type Server

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

func NewServer

func NewServer(opts NewServerOptions) *Server

func (*Server) Start

func (s *Server) Start() error

func (*Server) Stop

func (s *Server) Stop() error

Jump to

Keyboard shortcuts

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