response

package
v0.0.0-20260608 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Created

func Created(w http.ResponseWriter, data any)

Created writes a 201 Created JSON response.

func Download

func Download(w http.ResponseWriter, r *http.Request, filePath string, fileName string)

Download sends a file as a stream for downloading.

func Error

func Error(w http.ResponseWriter, status int, message string)

Error writes a JSON formatted error response.

func Flash

func Flash(w http.ResponseWriter, r *http.Request, key string, value any)

Flash stores a flash message in the session.

func FlashInput

func FlashInput(w http.ResponseWriter, r *http.Request)

FlashInput stores all input data in flash for next request.

func JSON

func JSON(w http.ResponseWriter, status int, data any)

JSON writes a JSON response with the given status code.

func Ok

func Ok(w http.ResponseWriter, data any)

Ok writes a 200 OK JSON response.

func Redirect

func Redirect(w http.ResponseWriter, r *http.Request, url string, status int)

Redirect sends an HTTP redirect response.

func RedirectBack

func RedirectBack(w http.ResponseWriter, r *http.Request, fallback string, status int)

RedirectBack redirects to the previous URL (from Referer header) or fallback.

func RedirectToRoute

func RedirectToRoute(w http.ResponseWriter, r *http.Request, name string, params map[string]string, status int)

RedirectToRoute redirects to a named route. Usage: response.RedirectToRoute(w, r, "user.show", map[string]string{"id": "1"}, http.StatusFound)

func Stream

func Stream(w http.ResponseWriter, callback func(w http.ResponseWriter)) error

Stream allows streaming a response back to the client using a callback.

func StreamLines

func StreamLines(w http.ResponseWriter, callback func(w http.ResponseWriter) error) error

StreamLines streams content line by line with a callback.

func StreamSSE

func StreamSSE(w http.ResponseWriter, events <-chan SSEEvent) error

StreamSSE streams Server-Sent Events to the client.

func StreamTimer

func StreamTimer(w http.ResponseWriter, interval time.Duration, callback func(int) string) error

StreamTimer streams events at regular intervals.

Types

type SSEEvent

type SSEEvent struct {
	ID    string
	Event string
	Data  string
	Retry int
}

SSEEvent represents a Server-Sent Event.

Jump to

Keyboard shortcuts

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