response

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTML

func HTML(body string) http.Handler

HTML response

func JSON

func JSON(props interface{}) http.Handler

JSON response

func RedirectPath

func RedirectPath(r *http.Request, subpath string) string

RedirectPath returns the response path.

Types

type Format

type Format struct {
	HTML http.Handler
	JSON http.Handler
}

Format returns different responses depending on the Accepts request header TODO: tighten up the types. Maybe HTML(w, r) & JSON(w, r) interfaces

func (*Format) ServeHTTP

func (f *Format) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Response

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

Response struct

func Status

func Status(code int) *Response

Status of a response

func (*Response) HTML

func (res *Response) HTML(body string) http.Handler

HTML responds with an HTML response.

func (*Response) JSON

func (res *Response) JSON(props interface{}) http.Handler

JSON responds with a JSON response.

func (*Response) Redirect

func (res *Response) Redirect(path string) http.Handler

Redirect to path

func (*Response) RedirectBack added in v0.2.0

func (res *Response) RedirectBack(fallback string) http.Handler

RedirectBack tries using the referrer to redirect to the previous page. If the referrer isn't set, it uses the fallback path.

func (*Response) ServeHTTP

func (res *Response) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Response) Set

func (res *Response) Set(key, value string) *Response

Set the header

Jump to

Keyboard shortcuts

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