response

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandlerStatus

func HandlerStatus(err error, fallback int) int

HandlerStatus returns a handler error status, or fallback for ordinary errors.

func NewHandlerError

func NewHandlerError(status int, message string, cause error) error

NewHandlerError creates an error suitable for generated handlers.

func WriteHTTP

func WriteHTTP(writer http.ResponseWriter, result Response) error

WriteHTTP writes a runtime response envelope to net/http.

func WriteNoStoreError

func WriteNoStoreError(writer http.ResponseWriter, status int, message string)

WriteNoStoreError writes an HTTP error that must not be cached.

func WriteNoStoreHTML

func WriteNoStoreHTML(writer http.ResponseWriter, request *http.Request, body string) error

WriteNoStoreHTML writes a no-store HTML response and suppresses the body for HEAD requests.

func WriteNoStoreHTTP

func WriteNoStoreHTTP(writer http.ResponseWriter, result Response) error

WriteNoStoreHTTP writes a response envelope that must not be cached.

Types

type HandlerError

type HandlerError struct {
	Status  int
	Message string
	Cause   error
}

HandlerError wraps failures raised by generated handlers.

func (HandlerError) Error

func (err HandlerError) Error() string

func (HandlerError) Unwrap

func (err HandlerError) Unwrap() error

type Kind

type Kind string

Kind identifies the response shape produced by actions, fragments, APIs, or full-page rendering.

const (
	HTML     Kind = "html"
	Redirect Kind = "redirect"
	Fragment Kind = "fragment"
	JSON     Kind = "json"
)

type Response

type Response struct {
	Kind   Kind
	Status int
	Body   string
	Target string
	Swap   SwapMode
	URL    string
}

Response is the generated runtime response envelope.

func FragmentFor

func FragmentFor(target, body string) Response

FragmentFor creates a partial fragment response for a DOM target.

func FragmentSwap

func FragmentSwap(target string, swap SwapMode, body string) (Response, error)

FragmentSwap creates a partial fragment response with an explicit swap mode.

func HTMLBody

func HTMLBody(status int, body string) Response

HTMLBody creates a full HTML response.

func JSONBody

func JSONBody(status int, body string) Response

JSONBody creates a JSON response from an already-encoded body.

func JSONValue

func JSONValue(status int, value any) (Response, error)

JSONValue marshals a value into a JSON response body.

func RedirectTo

func RedirectTo(url string) Response

RedirectTo creates a redirect response.

type SwapMode

type SwapMode string

SwapMode identifies how a fragment response should update its target.

const (
	SwapInnerHTML SwapMode = "innerHTML"
	SwapOuterHTML SwapMode = "outerHTML"
)

Jump to

Keyboard shortcuts

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