response

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2021 License: MIT Imports: 7 Imported by: 0

README

Response

Where response is a sub package of rocket, it's designed for simplifying the response creation task.

And also is designed to can work independently as a module, so you can see it implements the interface http.Handler

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Headers

type Headers map[string]string

Headers helps code be more readable

type Html added in v0.12.2

type Html string

Html is a mark for text is HTML return "Content-Type": "text/html"

type Json added in v0.12.2

type Json string

Json will return "Content-Type": "application/json"

type KeepFunc added in v0.13.0

type KeepFunc func(w http.ResponseWriter) (keep bool)

type Response

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

Response provide an abstraction for detailed HTTP response

func File added in v0.13.0

func File(filepath string) *Response

File would create a response for file resource by provided filepath

func New

func New(body interface{}) *Response

New would create a new response by provided body

func Redirect added in v1.1.0

func Redirect(path string) *Response

Redirect returns a response redirect to provided path

func Stream added in v0.13.0

func Stream(f KeepFunc) *Response

func (*Response) ContentType added in v0.13.0

func (res *Response) ContentType(value string) *Response

ContentType would change content-type of response by provided value

func (*Response) Cookies added in v0.12.2

func (res *Response) Cookies(cookies ...*cookie.Cookie) *Response

Cookies would update cookies of response by provided cookies

func (*Response) Headers

func (res *Response) Headers(headers Headers) *Response

Headers would update headers of response by provided headers

func (*Response) ServeHTTP added in v0.13.0

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

func (*Response) Status added in v0.12.3

func (res *Response) Status(code int) *Response

Status would change the status code of response by provided code, it would panic if you call it twice on the same response or you provide a invalid status code.

NOTE: According to https://tools.ietf.org/html/rfc2616#section-6.1.1 > The Status-Code element is a 3-digit integer

Jump to

Keyboard shortcuts

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