respond

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2020 License: Apache-2.0 Imports: 6 Imported by: 12

Documentation

Overview

Library respond creates convreq.HttpResponse objects. These can be returned from HTTP handlers to respond something to the client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(msg string) internal.HttpResponse

BadRequest creates a HTTP 400 Bad Request response.

func Error

func Error(err error) internal.HttpResponse

Error creates a HTTP 500 Internal Server Error response.

func Handler

func Handler(h http.Handler) internal.HttpResponse

Handler creates a response that delegates to a regular http.Handler.

func InternalServerError

func InternalServerError(msg string) internal.HttpResponse

InternalServerError creates a HTTP 500 Internal Server Error response.

func NotFound

func NotFound(msg string) internal.HttpResponse

NotFound creates a HTTP 404 Not Found response.

func OverrideResponseCode

func OverrideResponseCode(hr internal.HttpResponse, code int) internal.HttpResponse

OverrideResponseCode wraps a response to override the status code with the one given to this function. Note that this replaces the original ResponseWriter with an internal one, possibly not implementing interfaces like Flusher.

func PermissionDenied

func PermissionDenied(msg string) internal.HttpResponse

PermissionDenied creates a HTTP 403 Permission Denied response.

func Printf

func Printf(format string, v ...interface{}) internal.HttpResponse

Printf creates a response that sends a formatted string back to the client.

func Reader

func Reader(r io.Reader) internal.HttpResponse

Reader creates a response that copies everything from the reader to the client.

func Redirect

func Redirect(code int, url string) internal.HttpResponse

Redirect creates a response that redirects to another URL.

func RenderTemplate

func RenderTemplate(tpl Template, data interface{}) internal.HttpResponse

RenderTemplate creates a response that will render the given template.

func String

func String(data string) internal.HttpResponse

String creates a response that sends a string back to the client.

func WithHeader

func WithHeader(hr internal.HttpResponse, header, value string) internal.HttpResponse

WithHeader wraps a response and adds an additional header to be set.

func WithHeaders

func WithHeaders(hr internal.HttpResponse, headers http.Header) internal.HttpResponse

WithHeaders wraps a response and adds additional headers to be set.

Types

type Template

type Template interface {
	Execute(wr io.Writer, data interface{}) error
}

Template is a template-like object, like text/template.Template.

Jump to

Keyboard shortcuts

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