kit

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(h HandlerFunc) http.HandlerFunc

Handler converts a Kit.HandlerFunc to an http.HandlerFunc

func NotFoundHandler

func NotFoundHandler() http.HandlerFunc

NotFoundHandler returns a handler for 404 errors

func UseErrorHandler

func UseErrorHandler(h ErrorHandlerFunc)

UseErrorHandler sets a custom error handler for all Kit handlers

Types

type ErrorHandlerFunc

type ErrorHandlerFunc func(kit *Kit, err error)

ErrorHandlerFunc is the signature for custom error handlers

type HandlerFunc

type HandlerFunc func(kit *Kit) error

HandlerFunc is the signature for Twine handlers that return errors

type Kit

type Kit struct {
	Response http.ResponseWriter
	Request  *http.Request
}

Kit wraps http.ResponseWriter and *http.Request for convenient access

func (*Kit) Authorization

func (k *Kit) Authorization() (string, error)

Authorization extracts the authorization token from cookie or header

func (*Kit) Bytes

func (k *Kit) Bytes(status int, b []byte) error

Bytes writes raw bytes as a response

func (*Kit) Decode

func (k *Kit) Decode(v any) error

Decode decodes the request body into v based on Content-Type

func (*Kit) GetContext

func (k *Kit) GetContext(key string) string

GetContext retrieves a context value from the request

func (*Kit) GetCookie

func (k *Kit) GetCookie(key string) (string, error)

GetCookie retrieves a cookie value

func (*Kit) GetHeader

func (k *Kit) GetHeader(key string) string

GetHeader returns a request header value

func (*Kit) HTML

func (k *Kit) HTML(status int, htmlContent string) error

HTML writes raw HTML content

func (*Kit) IsAjax

func (k *Kit) IsAjax() bool

IsAjax returns true if the request is an Ajax request (from Alpine Ajax)

func (*Kit) JSON

func (k *Kit) JSON(status int, v any) error

JSON writes a JSON response

func (*Kit) NoContent

func (k *Kit) NoContent() error

NoContent writes a 204 No Content response

func (*Kit) PathValue

func (k *Kit) PathValue(key string) string

PathValue extracts a path parameter by key

func (*Kit) Redirect

func (k *Kit) Redirect(url string) error

Redirect performs an HTTP redirect using standard Location header

func (*Kit) Render

func (k *Kit) Render(name string, data any) error

Render automatically chooses between full and partial rendering based on X-Alpine-Request header

func (*Kit) RenderPartial

func (k *Kit) RenderPartial(name string, data any) error

RenderPartial renders a template component (for Ajax partial responses)

func (*Kit) RenderTemplate

func (k *Kit) RenderTemplate(name string, data any) error

RenderTemplate renders a full page template

func (*Kit) SetContext

func (k *Kit) SetContext(key, value string)

SetContext sets a context value on the request

func (*Kit) SetCookie

func (k *Kit) SetCookie(key, value string)

SetCookie sets an HTTP cookie

func (*Kit) Text

func (k *Kit) Text(status int, msg string) error

Text writes a plain text response

Jump to

Keyboard shortcuts

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