Documentation ¶
Index ¶
- Constants
- Variables
- type Context
- func (c *Context) BindJSON(v any) error
- func (c *Context) Context() context.Context
- func (c *Context) Get(key string) any
- func (c *Context) HTML(status int, v string) error
- func (c *Context) IsTLS() bool
- func (c *Context) IsWebSocket() bool
- func (c *Context) JSON(status int, v any) error
- func (c *Context) NoContent(status int) error
- func (c *Context) Param(key string) string
- func (c *Context) Redirect(code int, url string) error
- func (c *Context) Render(component templ.Component) error
- func (c *Context) RenderWithStatus(status int, component templ.Component) error
- func (c *Context) Scheme() string
- func (c *Context) Set(key string, value any)
- func (c *Context) String(status int, v string) error
- type Error
- type ErrorHandler
- type Handler
- type Kit
- func (k *Kit) Add(method string, pattern string, handler Handler, plugs ...Plug)
- func (k *Kit) Connect(pattern string, handler Handler, plugs ...Plug)
- func (k *Kit) Delete(pattern string, handler Handler, plugs ...Plug)
- func (k *Kit) Get(pattern string, handler Handler, plugs ...Plug)
- func (k *Kit) Head(pattern string, handler Handler, plugs ...Plug)
- func (k *Kit) Mux() chi.Router
- func (k *Kit) NotFound(handler Handler)
- func (k *Kit) Options(pattern string, handler Handler, plugs ...Plug)
- func (k *Kit) Patch(pattern string, handler Handler, plugs ...Plug)
- func (k *Kit) Plug(plugs ...Plug)
- func (k *Kit) Post(pattern string, handler Handler, plugs ...Plug)
- func (k *Kit) Put(pattern string, handler Handler, plugs ...Plug)
- func (k *Kit) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (k *Kit) Start(address string) error
- func (k *Kit) Static(pattern string, staticDir string, plugs ...Plug)
- func (k *Kit) Trace(pattern string, handler Handler, plugs ...Plug)
- type Plug
- type Schema
Constants ¶
const ErrorKey = "error"
ErrorKey is the key used to store the error in the context.
Variables ¶
var DefaultErrorHandler = func(ctx *Context, err error) error { return ctx.String(http.StatusInternalServerError, err.Error()) }
DefaultErrorHandler is the default error handler that is called when a route handler returns an error.
var DefaultNotFoundHandler = func(ctx *Context) error { return ctx.String(http.StatusNotFound, "Not Found") }
DefaultNotFoundHandler is the default handler that is called when no route matches the request.
var PingHandler = func(ctx *Context) error { return ctx.String(http.StatusOK, "PONG") }
PingHandler is a handler that returns a PONG response for health requests.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct { Response http.ResponseWriter Request *http.Request }
Context represents the context of the current HTTP request. It holds request and response objects, path, path parameters, data and registered handler.
func NewContext ¶
func NewContext(w http.ResponseWriter, r *http.Request) *Context
NewContext creates a new Context instance.
func (*Context) BindJSON ¶
BindJSON decodes the JSON request body and stores the result in the value pointed to by v.
func (*Context) HTML ¶
HTML writes an HTML response with the provided status code and data. The header is set to text/html; charset=utf-8 TODO: Unit test this func.
func (*Context) IsWebSocket ¶
IsWebSocket returns true if HTTP connection is WebSocket otherwise false.
func (*Context) JSON ¶
JSON writes a JSON response with the provided status code and data. The header is set to application/json.
func (*Context) NoContent ¶
NoContent sends a response with no response body and the provided status code.
func (*Context) Redirect ¶
Redirect performs an HTTP redirect to the specified URL with the given status code.
func (*Context) RenderWithStatus ¶
RenderWithStatus renders a templated component to the response writer with the specified status code.
type Error ¶
Error represents an HTTP error.
type ErrorHandler ¶
ErrorHandler is a centralized HTTP error handler.
type Handler ¶
Handler is a function that handles HTTP requests.
func WrapHandler ¶
WrapHandler is a helper function for wrapping http.Handler and returns a WebKit middleware.
func WrapHandlerFunc ¶
func WrapHandlerFunc(f http.HandlerFunc) Handler
WrapHandlerFunc is a helper function for wrapping http.HandlerFunc and returns a WebKit middleware.
type Kit ¶
type Kit struct { ErrorHandler ErrorHandler NotFoundHandler Handler // contains filtered or unexported fields }
Kit is the top-level framework instance for handling HTTP routes.
Goroutine safety: Do not mutate WebKit instance fields after server has started. Accessing these fields from handlers/middlewares and changing field values at the same time leads to data-races. Adding new routes after the server has been started is also not safe!
func (*Kit) Add ¶
Add registers a new route for an HTTP method and path with matching handler in the router with optional route-level plugs.
func (*Kit) Connect ¶
Connect registers a new CONNECT route for a path with matching handler in the router with optional route-level plugs.
func (*Kit) Delete ¶
Delete registers a new DELETE route for a path with matching handler in the router with optional route-level plugs.
func (*Kit) Get ¶
Get registers a new GET route for a path with matching handler in the router with optional route-level plugs.
func (*Kit) Head ¶
Head registers a new HEAD route for a path with matching handler in the router with optional route-level plugs.
func (*Kit) NotFound ¶
NotFound sets a custom http.HandlerFunc for routing paths that could not be found. The default 404 handler is `http.NotFound`.
func (*Kit) Options ¶
Options registers a new OPTIONS route for a path with matching handler in the router with optional route-level plugs.
func (*Kit) Patch ¶
Patch registers a new PATCH route for a path with matching handler in the router with optional route-level plugs.
func (*Kit) Plug ¶
Plug adds a middleware function to the chain. These are called after the funcs that are passed directly to the route-level handlers.
For example: app.Plug(middleware.Logger)
func (*Kit) Post ¶
Post registers a new POST route for a path with matching handler in the router with optional route-level plugs.
func (*Kit) Put ¶
Put registers a new PUT route for a path with matching handler in the router with optional route-level plugs.
func (*Kit) ServeHTTP ¶
func (k *Kit) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface.