Documentation
¶
Index ¶
- type Context
- func (c *Context) BindForm(v interface{}) error
- func (c *Context) BindJSON(v interface{}) error
- func (c *Context) BindMultipartForm(v interface{}, maxMemory int64) error
- func (c *Context) Broadcast(endpoint string, message []byte)
- func (c *Context) BroadcastToAll(message []byte)
- func (c *Context) Cookie(name string) (*http.Cookie, error)
- func (c *Context) DB() *sqlx.DB
- func (c *Context) DeleteCookie(name string) error
- func (c *Context) Get(key string) any
- func (c *Context) GetContext() context.Context
- func (c *Context) GetEventManager() *events.EventManager
- func (c *Context) GetHeader(name string) string
- func (c *Context) GetLogger() *logger.Logger
- func (c *Context) GetParam(key string) string
- func (c *Context) GetParams() httprouter.Params
- func (c *Context) GetQueryParam(key string) string
- func (c *Context) GetRequest() *http.Request
- func (c *Context) GetResponse() http.ResponseWriter
- func (c *Context) Redirect(status StatusCode, url string) error
- func (c *Context) RenderTempl(component templ.Component) error
- func (c *Context) SendFile(filePath string) error
- func (c *Context) SendHTML(status StatusCode, data string) error
- func (c *Context) SendJSON(status StatusCode, data interface{}) error
- func (c *Context) SendString(status StatusCode, data string) error
- func (c *Context) Set(key string, value any)
- func (c *Context) SetContext(ctx context.Context)
- func (c *Context) SetCookie(config CookieConfig)
- func (c *Context) SetHeader(name, value string)
- func (c *Context) Status(status StatusCode)
- type ContextType
- type CookieConfig
- type ErrorHandler
- type Handler
- type Json
- type Middleware
- type Pulse
- func (p *Pulse) Delete(path string, h Handler, m ...Middleware)
- func (p *Pulse) Get(path string, h Handler, m ...Middleware)
- func (p *Pulse) GetDatabase() *database.Database
- func (p *Pulse) GetEventManager() *events.EventManager
- func (p *Pulse) GetLogger() *logger.Logger
- func (p *Pulse) Head(path string, h Handler, m ...Middleware)
- func (p *Pulse) Options(path string, h Handler, m ...Middleware)
- func (p *Pulse) Patch(path string, h Handler, m ...Middleware)
- func (p *Pulse) Post(path string, h Handler, m ...Middleware)
- func (p *Pulse) Put(path string, h Handler, m ...Middleware)
- func (p *Pulse) SetErrorHandler(errorHandler ErrorHandler)
- func (p *Pulse) SetLogger(config logger.Config)
- func (p *Pulse) Start(listenAddr string) error
- func (p *Pulse) Static(basePath string, directoryPath string)
- func (p *Pulse) Use(m ...Middleware)
- func (p *Pulse) WebSocket(endpoint string, m ...Middleware)
- func (p *Pulse) WithDatabase(config database.Config) *Pulse
- type SameSite
- type StatusCode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context holds the request, response, and various utilities for handling HTTP requests.
func (*Context) BindForm ¶
BindForm reads the Form body from the request and unmarshals it into the provided value.
func (*Context) BindJSON ¶
BindJSON reads the JSON body from the request and unmarshals it into the provided value.
func (*Context) BindMultipartForm ¶
BindMultipartForm reads the multipart form body from the request and unmarshals it into the provided value.
func (*Context) Broadcast ¶ added in v0.2.0
Broadcast sends a message to all connected WebSocket clients for a specific endpoint.
func (*Context) BroadcastToAll ¶ added in v0.2.0
BroadcastToAll sends a message to all connected WebSocket clients across all endpoints.
func (*Context) Cookie ¶ added in v0.3.3
GetCookie retrieves a specific cookie by name from the request.
func (*Context) DeleteCookie ¶ added in v0.3.2
DeleteCookie removes a cookie from the clients browser
func (*Context) GetContext ¶
GetContext returns the context.Context associated with the context.
func (*Context) GetEventManager ¶ added in v0.2.0
func (c *Context) GetEventManager() *events.EventManager
GetEventManager returns the event manager associated with the context.
func (*Context) GetParams ¶
func (c *Context) GetParams() httprouter.Params
GetParams returns the URL parameters from the router associated with the context.
func (*Context) GetQueryParam ¶
GetQueryParam retrieves a specific query parameter by key from the request URL.
func (*Context) GetRequest ¶
GetRequest returns the HTTP request associated with the context.
func (*Context) GetResponse ¶
func (c *Context) GetResponse() http.ResponseWriter
GetResponse returns the HTTP response writer associated with the context.
func (*Context) Redirect ¶
func (c *Context) Redirect(status StatusCode, url string) error
Redirect performs an HTTP redirect to the specified URL with the given status code.
func (*Context) RenderTempl ¶
RenderTempl renders a templ template
func (*Context) SendHTML ¶
func (c *Context) SendHTML(status StatusCode, data string) error
SendHTML sends an HTML response with the given status code.
func (*Context) SendJSON ¶
func (c *Context) SendJSON(status StatusCode, data interface{}) error
SendJSON sends a JSON response with the given status code.
func (*Context) SendString ¶
func (c *Context) SendString(status StatusCode, data string) error
SendString sends a plain text response with the given status code.
func (*Context) SetContext ¶
SetContext updates the context.Context associated with the context.
func (*Context) SetCookie ¶
func (c *Context) SetCookie(config CookieConfig)
SetCookie sets a cookie in the response.
func (*Context) Status ¶
func (c *Context) Status(status StatusCode)
Status sets the HTTP status code for the response.
type ContextType ¶
type ContextType string
type CookieConfig ¶
type CookieConfig struct { // Name is the name of the cookie. Name string // Value is the value of the cookie. Value string // MaxAge specifies the maximum age in seconds for the cookie. // A zero or negative value means that the cookie is a session cookie. MaxAge int // Path specifies the URL path that the cookie is valid for. Path string // Domain specifies the domain that the cookie is valid for. Domain string // Secure indicates whether the cookie should only be sent over secure (HTTPS) connections. Secure bool // HttpOnly indicates whether the cookie is inaccessible to JavaScript (i.e., client-side scripts). HttpOnly bool // SameSite specifies the SameSite attribute for the cookie, controlling cross-site request behavior. SameSite SameSite }
CookieConfig holds configuration options for setting cookies.
type ErrorHandler ¶
ErrorHandler defines a function type for handling errors in the context of an HTTP request. It takes an error and a Context object, and returns an error which can be used for additional processing.
type Handler ¶
Handler is a function type for processing HTTP requests. It takes a *Context and returns an error.
type Middleware ¶
Middleware is a function type that wraps a Handler. It takes a Handler as input and returns a new Handler.
type Pulse ¶
type Pulse struct {
// contains filtered or unexported fields
}
Pulse represents the main application struct with middleware, router, database, and logger.
func (*Pulse) Delete ¶
func (p *Pulse) Delete(path string, h Handler, m ...Middleware)
Register HTTP methods with handlers and optional route-specific middleware.
func (*Pulse) GetDatabase ¶ added in v0.2.2
GetDatabase returns the database connected to the pulse app
func (*Pulse) GetEventManager ¶ added in v0.2.2
func (p *Pulse) GetEventManager() *events.EventManager
GetEventManager returns the event manager in the pulse app
func (*Pulse) SetErrorHandler ¶
func (p *Pulse) SetErrorHandler(errorHandler ErrorHandler)
SetErrorHandler sets a new error handler in the Pulse struct.
func (*Pulse) Static ¶ added in v0.1.4
Static sets up a handler to serve static files from the specified directory.
func (*Pulse) Use ¶
func (p *Pulse) Use(m ...Middleware)
Use adds global middleware to be applied to all routes.
func (*Pulse) WebSocket ¶ added in v0.2.0
func (p *Pulse) WebSocket(endpoint string, m ...Middleware)
WebSocketHandler sets up a WebSocket handler with optional middleware.
type SameSite ¶
type SameSite int
SameSite represents the SameSite attribute for cookies, which controls whether and when cookies are sent with cross-site requests.
const ( // SameSiteDefaultMode allows the browser to choose the SameSite policy // based on its own rules and defaults. SameSiteDefaultMode SameSite = iota + 1 // SameSiteLaxMode allows cookies to be sent with top-level navigations // and will be sent with GET requests from third-party contexts. SameSiteLaxMode // SameSiteStrictMode ensures cookies are only sent in a first-party context, // and not sent with requests from other sites. SameSiteStrictMode // SameSiteNoneMode allows cookies to be sent with cross-site requests, // but requires the Secure attribute to be set. SameSiteNoneMode )
type StatusCode ¶
type StatusCode int
StatusCode represents HTTP status codes.
const ( // StatusContinue indicates that the initial part of a request has been received and has not yet been rejected by the server. StatusContinue StatusCode = 100 // StatusSwitchingProtocols indicates that the server is switching protocols as requested by the client. StatusSwitchingProtocols StatusCode = 101 )
const ( // StatusOK indicates that the request was successful. StatusOK StatusCode = 200 // StatusCreated indicates that the request was successful and a resource was created. StatusCreated StatusCode = 201 // StatusAccepted indicates that the request has been accepted for processing, but the processing is not yet complete. StatusAccepted StatusCode = 202 // StatusNonAuthoritative indicates that the request was successful, but the response is from a different source than the original server. StatusNonAuthoritative StatusCode = 203 // StatusNoContent indicates that the request was successful, but there is no content to send in the response. StatusNoContent StatusCode = 204 // StatusResetContent indicates that the request was successful, but the client should reset the document view. StatusResetContent StatusCode = 205 // StatusPartialContent indicates that the server is delivering only part of the resource due to a range header sent by the client. StatusPartialContent StatusCode = 206 )
const ( // StatusMultipleChoices indicates that there are multiple options for the resource the client may follow. StatusMultipleChoices StatusCode = 300 // StatusMovedPermanently indicates that the resource has been moved permanently to a new URL. StatusMovedPermanently StatusCode = 301 // StatusFound indicates that the resource resides temporarily under a different URL. StatusFound StatusCode = 302 // StatusSeeOther indicates that the response to the request can be found under another URL using the GET method. StatusSeeOther StatusCode = 303 // StatusNotModified indicates that the resource has not been modified since the last request. StatusNotModified StatusCode = 304 // StatusUseProxy indicates that the requested resource must be accessed through a proxy. StatusUseProxy StatusCode = 305 // StatusTemporaryRedirect indicates that the request should be redirected temporarily. StatusTemporaryRedirect StatusCode = 307 // StatusPermanentRedirect indicates that the request should be redirected permanently. StatusPermanentRedirect StatusCode = 308 )
const ( // StatusBadRequest indicates that the server could not understand the request due to invalid syntax. StatusBadRequest StatusCode = 400 StatusUnauthorized StatusCode = 401 // StatusPaymentRequired indicates that payment is required to access the requested resource. StatusPaymentRequired StatusCode = 402 // StatusForbidden indicates that the server understood the request but refuses to authorize it. StatusForbidden StatusCode = 403 // StatusNotFound indicates that the requested resource could not be found. StatusNotFound StatusCode = 404 // StatusMethodNotAllowed indicates that the request method is not allowed for the requested resource. StatusMethodNotAllowed StatusCode = 405 // StatusNotAcceptable indicates that the server cannot produce a response matching the list of acceptable values defined in the request's headers. StatusNotAcceptable StatusCode = 406 // StatusProxyAuthRequired indicates that the client must authenticate itself to use a proxy. StatusProxyAuthRequired StatusCode = 407 // StatusRequestTimeout indicates that the server timed out waiting for the request. StatusRequestTimeout StatusCode = 408 // StatusConflict indicates that the request could not be processed due to a conflict in the request. StatusConflict StatusCode = 409 // StatusGone indicates that the resource requested is no longer available and will not be available again. StatusGone StatusCode = 410 // StatusLengthRequired indicates that the request is missing a Content-Length header field. StatusLengthRequired StatusCode = 411 // StatusPreconditionFailed indicates that one or more conditions in the request header fields were not met. StatusPreconditionFailed StatusCode = 412 // StatusPayloadTooLarge indicates that the request is larger than the server is willing or able to process. StatusPayloadTooLarge StatusCode = 413 // StatusURITooLong indicates that the URI provided was too long for the server to process. StatusURITooLong StatusCode = 414 // StatusUnsupportedMediaType indicates that the server refuses to accept the request because the resource is in a format not supported by the server. StatusUnsupportedMediaType StatusCode = 415 // StatusRangeNotSatisfiable indicates that the server cannot provide the requested range of the resource. StatusRangeNotSatisfiable StatusCode = 416 // StatusExpectationFailed indicates that the server cannot meet the requirements of the Expect request-header field. StatusExpectationFailed StatusCode = 417 )
const ( // StatusInternalServerError indicates that the server encountered an unexpected condition that prevented it from fulfilling the request. StatusInternalServerError StatusCode = 500 // StatusNotImplemented indicates that the server does not support the functionality required to fulfill the request. StatusNotImplemented StatusCode = 501 // StatusBadGateway indicates that the server, while acting as a gateway or proxy, received an invalid response from the upstream server. StatusBadGateway StatusCode = 502 StatusServiceUnavailable StatusCode = 503 // StatusGatewayTimeout indicates that the server, while acting as a gateway or proxy, did not receive a timely response from the upstream server. StatusGatewayTimeout StatusCode = 504 // StatusHTTPVersionNotSupported indicates that the server does not support the HTTP protocol version that was used in the request. StatusHTTPVersionNotSupported StatusCode = 505 )