response

package
v2.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: BSD-3-Clause Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes added in v2.6.0

func Bytes(ctype string, data []byte, opts ...Option) (*router.Response, error)

Produce a successful response with a byte entity. The status code used is 200 unless otherwise specified via an option.

func HTML added in v2.1.0

func HTML(fstr string, data interface{}, opts ...Option) (*router.Response, error)

Produce a successful 200 response with HTML entity content. The template string is expected to use the Go template (HTML variant) format, and it will be evaluated with the provided context value. The result of this evaluation is the response entity.

func JSON added in v2.3.0

func JSON(body interface{}, opts ...Option) *router.Response

Produce a successful response, optionally including a payload, which will be marshaled to JSON. The status code used is 200 unless otherwise specified via an option.

func Reader added in v2.6.0

func Reader(ctype string, rdr io.Reader, opts ...Option) (*router.Response, error)

Produce a successful response with a reader entity. The status code used is 200 unless otherwise specified via an option.

func Redirect

func Redirect(dest string, opts ...Option) *router.Response

Produce a 302/Found redirect response

func Success deprecated

func Success(body interface{}, opts ...Option) *router.Response

Produce a successful response, optionally including a payload, which will be marshaled to JSON. The status code used is 200 unless otherwise specified via an option.

Deprecated: This method has been deprecated in favor of JSON(), which it simply calls.

func Text added in v2.2.0

func Text(ctype, text string, opts ...Option) (*router.Response, error)

Produce a successful response with a text entity. The status code used is 200 unless otherwise specified via an option.

Types

type Config

type Config struct {
	Status int
	Header http.Header
	Funcs  template.FuncMap
}

func (Config) WithOptions

func (c Config) WithOptions(opts []Option) Config

type Option

type Option func(Config) Config

func WithFuncs added in v2.1.0

func WithFuncs(f template.FuncMap) Option

func WithHeader

func WithHeader(k, v string) Option

func WithHeaders

func WithHeaders(h map[string]string) Option

func WithStatus added in v2.3.0

func WithStatus(s int) Option

Jump to

Keyboard shortcuts

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