Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App interface {
// OnStart runs the given callback immediately before the sever starts.
OnStart(callback func())
// On stop runs the given callback immediately before the server stops.
OnStop(callback func())
// OnHandlerError runs the given callback as a central error handler.
OnHandlerError(callback func(c Context, err error))
// Start runs the http server on the given port number.
Start(port int) error
// Stop sends a stop signal to the http server.
Stop() error
// Use applies the given middleware to all registered handlers.
Use(middleware ...MiddlewareFunc)
// Any registers a handler for any HTTP request method.
Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc)
// GET registers a handler for HTTP GET requests.
GET(path string, handler HandlerFunc, middleware ...MiddlewareFunc)
// POST registers a handler for HTTP POST requests.
POST(path string, handler HandlerFunc, middleware ...MiddlewareFunc)
// PUT registers a handler for HTTP PUT requests.
PUT(path string, handler HandlerFunc, middleware ...MiddlewareFunc)
// DELETE registers a handler for HTTP DELETE requests.
DELETE(path string, handler HandlerFunc, middleware ...MiddlewareFunc)
// HEAD registers a handler for HTTP HEAD requests.
HEAD(path string, handler HandlerFunc, middleware ...MiddlewareFunc)
// OPTIONS registers a handler for HTTP OPTIONS requests.
OPTIONS(path string, handler HandlerFunc, middleware ...MiddlewareFunc)
// CONNECT registers a handler for HTTP CONNECT requests.
CONNECT(path string, handler HandlerFunc, middleware ...MiddlewareFunc)
// TRACE registers a handler for HTTP TRACE requests.
TRACE(path string, handler HandlerFunc, middleware ...MiddlewareFunc)
// PATCH registers a handler for HTTP PATCH requests.
PATCH(path string, handler HandlerFunc, middleware ...MiddlewareFunc)
}
App defines the interface for the central application.
type Context ¶
type Context interface {
// Request returns the underlying request.
Request() *http.Request
// Response returns the underlying response writer.
Response() http.ResponseWriter
// Set adds the key value pair to the context store.
Set(key string, value any)
// Get returns the value mapped to by the given key from the context store if
// it exists.
Get(key string) (any, bool)
// DB returns the underlying database.
DB() *database.Database
// Mailer returns the underlying mailer.
Mailer() mailer.Mailer
// Auth returns the current auth session.
Auth() auth.Auth
// Session returns the unique user session.
Session() sessions.Session
// HTML writes the given status and html string to the response.
HTML(status int, html string) error
// JSON writes the given status and json data to the response.
JSON(status int, data any) error
// String writes the given status and string to the response.
String(status int, text string) error
// NoContent writes the given status to the response without a body.
NoContent(status int) error
// NotFound writes a status 404 to the response without a body.
NotFound() error
// Render writes the given status and templates to the response.
Render(status int, tpls ...templ.Component) error
// Redirect is a HTMX aware redirect method.
// Non-HTMX requests result in a redirect to the given path with status.
// HTMX requests return a 200 - OK status with HTMX redirect headers.
// https://github.com/bigskysoftware/htmx/issues/2052#issuecomment-1979805051
Redirect(status int, path string) error
// IsHTMX returns true if the current request is HTMX, otherwise false.
IsHTMX() bool
}
Context defines the request scoped context.
type HandlerFunc ¶
type MiddlewareFunc ¶
type MiddlewareFunc func(next HandlerFunc) HandlerFunc
Click to show internal directories.
Click to hide internal directories.