internal

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const StatusStopPolling = 286

StatusStopPolling is the HTTP status code (286) that tells HTMX to stop polling when using hx-trigger="every Xs".

Variables

This section is empty.

Functions

func NewContext

func NewContext(req *http.Request, res http.ResponseWriter) *contextImpl

NewContext creates a new request-scoped context and stores itself as a value for retrieval via ViewContext.

func SetAuth

func SetAuth[T any](ctx context.Context, auth T) context.Context

SetAuth stores the authenticated entity in the context for later retrieval via AuthContext[T].Auth().

Types

type AuthContext

type AuthContext[T any] interface {
	Context

	// Auth returns the entity for the authenticated request.
	Auth() T
}

AuthContext extends Context with access to the authenticated entity of type T.

func NewAuthContext

func NewAuthContext[T any](ctx Context) AuthContext[T]

NewAuthContext wraps an existing Context into an AuthContext.

type Context

type Context interface {
	context.Context

	// URI returns the raw request URI.
	URI() string
	// Header returns the value of the named request header.
	Header(key string) string
	// Param returns the value of a path parameter (e.g. {id}).
	Param(key string) string

	// Cookie returns the value of the named cookie, or "" if absent.
	Cookie(name string) string
	// SetCookie sets an HttpOnly cookie with the given name, value, and max age.
	SetCookie(name, value string, maxAge time.Duration, secure bool)
	// DelCookie deletes the named cookie by setting MaxAge to -1.
	DelCookie(name string) Context

	// FormFile returns the first file for the given form field name.
	FormFile(name string) (multipart.File, *multipart.FileHeader, error)

	// SetStatus writes the HTTP status code to the response.
	SetStatus(status int)
	// Redirect sends a redirect response. For HTMX requests, it sets
	// the HX-Redirect header instead of a standard HTTP redirect.
	Redirect(url string) Result

	// IsAuthorized returns true if an auth entity has been set on the context.
	IsAuthorized() bool

	// HTMX returns the HTMX sub-interface for reading request headers
	// and writing response headers.
	HTMX() HTMX

	// SetValue stores a key-value pair in the context.
	SetValue(key, val any)

	// WithLayouts re-enables layout rendering for this request.
	WithLayouts() Context
	// WithoutLayouts disables layout rendering for this request.
	WithoutLayouts() Context
	// IsWithoutLayouts returns true if layouts have been disabled.
	IsWithoutLayouts() bool
}

Context is the request-scoped interface passed to all thx handlers. It extends context.Context with HTTP helpers for the current request.

func ViewContext

func ViewContext(ctx context.Context) Context

ViewContext retrieves the thx Context from a standard context.Context. This is needed because templ wraps contexts with context.WithValue, making direct type assertions fail. Panics if no thx Context is found — this indicates ViewContext was called outside of a thx request lifecycle (e.g. in a cached component rendered with context.Background).

type EmptyResult

type EmptyResult struct{}

EmptyResult is a Result that writes nothing to the response.

func (*EmptyResult) WriteResult

func (e *EmptyResult) WriteResult(_ http.ResponseWriter) error

WriteResult is a no-op for empty results.

type HTMX

type HTMX interface {
	// IsRequest returns true if this is an HTMX request (HX-Request: true).
	IsRequest() bool
	// IsPartial returns true if this is a partial HTMX request (not boosted).
	IsPartial() bool
	// IsBoosted returns true if this is an HTMX boosted request.
	IsBoosted() bool
	// CurrentURL returns the HX-Current-URL header value.
	CurrentURL() string
	// IsHistoryRestoreRequest returns true if HTMX is restoring history.
	IsHistoryRestoreRequest() bool
	// Source returns the ID of the element that triggered the request.
	Source() string
	// Target returns the ID of the target element for the response.
	Target() string

	// Location triggers a client-side navigation via HX-Location.
	Location(url string)
	// LocationWithOptions triggers a client-side navigation with fine-grained options.
	LocationWithOptions(opts LocationOptions) error
	// PushURL pushes the given URL onto the browser's history stack.
	PushURL(url string)
	// PreventPushURL prevents HTMX from pushing a URL to the history stack.
	PreventPushURL()
	// Redirect triggers a full-page redirect via HX-Redirect.
	Redirect(url string)
	// Refresh triggers a full page refresh via HX-Refresh.
	Refresh()
	// ReplaceURL replaces the current URL in the browser's location bar.
	ReplaceURL(url string)
	// PreventReplaceURL prevents HTMX from replacing the current URL.
	PreventReplaceURL()
	// Reswap overrides the swap strategy via HX-Reswap and returns a
	// SwapChain for adding modifiers like delays and scroll behavior.
	Reswap(strategy string) *SwapChain
	// Retarget overrides the target element via HX-Retarget.
	Retarget(selector string)
	// Reselect overrides which part of the response to swap via HX-Reselect.
	Reselect(selector string)
	// StopPolling sends HTTP 286 to stop HTMX polling.
	StopPolling()
	// Trigger fires a client-side event via HX-Trigger.
	// Returns a TriggerChain for adding multiple events.
	Trigger(event string, data any) *TriggerChain
}

HTMX provides access to HTMX request headers and response header setters.

type LocationOptions

type LocationOptions struct {
	Path    string `json:"path"`
	Source  string `json:"source,omitempty"`
	Event   string `json:"event,omitempty"`
	Handler string `json:"handler,omitempty"`
	Target  string `json:"target,omitempty"`
	Swap    string `json:"swap,omitempty"`
	Values  any    `json:"values,omitempty"`
	Headers any    `json:"headers,omitempty"`
	Select  string `json:"select,omitempty"`
}

LocationOptions configures a client-side HTMX navigation via HX-Location.

type Result

type Result interface {
	WriteResult(http.ResponseWriter) error
}

Result is the interface returned by all route handlers. Implementations write the handler's response to the http.ResponseWriter.

type SwapChain

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

func (*SwapChain) FocusScroll

func (s *SwapChain) FocusScroll(enabled bool) *SwapChain

FocusScroll enables or disables focus scrolling after swap.

func (*SwapChain) IgnoreTitle

func (s *SwapChain) IgnoreTitle() *SwapChain

IgnoreTitle prevents HTMX from updating the page title.

func (*SwapChain) ScrollBottom

func (s *SwapChain) ScrollBottom(selector string) *SwapChain

ScrollBottom scrolls to the bottom of the element matching the selector.

func (*SwapChain) ScrollTop

func (s *SwapChain) ScrollTop(selector string) *SwapChain

ScrollTop scrolls to the top of the element matching the selector.

func (*SwapChain) ScrollWindowBottom

func (s *SwapChain) ScrollWindowBottom() *SwapChain

ScrollWindowBottom scrolls the window to the bottom.

func (*SwapChain) ScrollWindowTop

func (s *SwapChain) ScrollWindowTop() *SwapChain

ScrollWindowTop scrolls the window to the top.

func (*SwapChain) SettleDelay

func (s *SwapChain) SettleDelay(d time.Duration) *SwapChain

SettleDelay adds a settle delay modifier.

func (*SwapChain) ShowBottom

func (s *SwapChain) ShowBottom(selector string) *SwapChain

ShowBottom shows the bottom of the element matching the selector in the viewport.

func (*SwapChain) ShowNone

func (s *SwapChain) ShowNone() *SwapChain

ShowNone disables automatic scrolling after swap.

func (*SwapChain) ShowTop

func (s *SwapChain) ShowTop(selector string) *SwapChain

ShowTop shows the top of the element matching the selector in the viewport.

func (*SwapChain) ShowWindowBottom

func (s *SwapChain) ShowWindowBottom() *SwapChain

ShowWindowBottom scrolls the window to show the bottom.

func (*SwapChain) ShowWindowTop

func (s *SwapChain) ShowWindowTop() *SwapChain

ShowWindowTop scrolls the window to show the top.

func (*SwapChain) SwapDelay

func (s *SwapChain) SwapDelay(d time.Duration) *SwapChain

SwapDelay adds a swap delay modifier.

func (*SwapChain) Transition

func (s *SwapChain) Transition() *SwapChain

Transition enables view transitions for this swap.

type TriggerChain

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

TriggerChain provides fluent chaining for HX-Trigger events. Each method updates the header immediately.

func (*TriggerChain) Trigger

func (t *TriggerChain) Trigger(event string, data any) *TriggerChain

Trigger adds an event to the HX-Trigger header. Pass nil for data to trigger an event with no payload.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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