httpc

package module
v0.0.0-...-b68d119 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2016 License: BSD-3-Clause Imports: 13 Imported by: 0

README

httpc

Package httpc implements HTTP request and response helpers.

Documentation

Overview

Package httpc implements HTTP request and response helpers.

Index

Constants

View Source
const DefaultMaxUploadSize int64 = 32 << 20 // 32 MB

DefaultMaxUploadSize is the default maximum file upload size in bytes.

Variables

This section is empty.

Functions

func Abort

func Abort(w http.ResponseWriter, code int) error

Abort replies to the request with a default plain text error.

func Error

func Error(req *http.Request) error

Error returns the error response if any.

func NoContent

func NoContent(w http.ResponseWriter) error

NoContent writes http.StatusNoContent to the header.

func Param

func Param(req *http.Request, name string) string

Param returns the bound parameter with the given name.

func Path

func Path(req *http.Request) string

Path returns the escaped request path.

func Pattern

func Pattern(req *http.Request) *pat.Pattern

Pattern returns the pattern corresponding to the most recently matched pattern, or nil if no pattern was matched.

func Query

func Query(req *http.Request, name string) string

Query returns the first query value associated with the given key. If there are no values associated with the key, Query returns the empty string.

func Redirect

func Redirect(w http.ResponseWriter, req *http.Request, path string, code int) error

Redirect replies to the request with a redirect to path. This is the equivalent to http.Redirect and is here for consistency.

func RedirectTo

func RedirectTo(w http.ResponseWriter, req *http.Request, format string, args ...interface{}) error

RedirectTo replies to the request with a redirect to the application path constructed from the format specifier and args.

func RemoteAddr

func RemoteAddr(req *http.Request) string

RemoteAddr returns a best guess remote address.

func Render

func Render(w http.ResponseWriter, req *http.Request, view Viewable, code int) error

Render writes the view in the requested format, if available.

func RenderHTML

func RenderHTML(w http.ResponseWriter, view Renderable, code int) error

RenderHTML writes the view as templated HTML.

func RenderJSON

func RenderJSON(w http.ResponseWriter, view Viewable, code int) error

RenderJSON writes the view as marshalled JSON.

func RenderPlain

func RenderPlain(w http.ResponseWriter, view Viewable, code int) error

RenderPlain writes the view as a string.

func ServeFile

func ServeFile(w http.ResponseWriter, req *http.Request, name string) error

ServeFile replies to the request with the contents of the named file. This is the equivalent to http.ServeFile and is here for consistency.

func SetCookie

func SetCookie(w http.ResponseWriter, cookie *http.Cookie)

SetCookie adds a Set-Cookie header to the provided http.ResponseWriter's headers. The provided cookie must have a valid Name. Invalid cookies may be silently dropped.

func Validate

func Validate(req *http.Request, form Form) error

Validate decodes, sanitizes and validates the request body and stores the result in to the value pointed to by form.

func ValidateForm

func ValidateForm(req *http.Request, form Form) error

ValidateForm decodes, sanitizes and validates the request body as a form and stores the result in the value pointed to by form.

func ValidateJSON

func ValidateJSON(req *http.Request, form Form) error

ValidateJSON decodes, sanitizes and validates the request body as JSON and stores the result in the value pointed to by form.

func ValidateMultipart

func ValidateMultipart(req *http.Request, form Form) error

ValidateMultipart decodes, sanitizes and validates the request body as multipart/form-data and stores the result in the value pointed to by form.

Types

type Form

type Form interface {
	// Validate sanitizes and validates the form.
	Validate() error
}

A Form represents a form with validation.

type Handler

type Handler func(w http.ResponseWriter, req *http.Request) error

Handler represents a HTTP handler with error handling.

type Mux

type Mux struct {
	*goji.Mux
	// contains filtered or unexported fields
}

Mux represents an HTTP request multiplexer.

func NewMux

func NewMux() *Mux

NewMux returns a new mux.

func (*Mux) Any

func (m *Mux) Any(p string, h Handler)

Any registers a route that matches any HTTP method.

func (*Mux) Delete

func (m *Mux) Delete(p string, h Handler)

Delete registers a route that only matches the DELETE HTTP method.

func (*Mux) FileServer

func (m *Mux) FileServer(p string, fs http.FileSystem)

FileServer registers a file system with the mux. The pattern p is expected to be a prefix wildcard route. See https://godoc.org/goji.io/pat#hdr-Prefix_Matches. The pattern prefix is removed from the request URL before handled.

func (*Mux) Get

func (m *Mux) Get(p string, h Handler)

Get registers a route that only matches the GET and HEAD HTTP methods. HEAD requests are handled transparently by net/http.

func (*Mux) Handle

func (m *Mux) Handle(p string, h http.Handler)

Handle registers a standard net/http route with the mux.

func (*Mux) Head

func (m *Mux) Head(p string, h Handler)

Head registers a route that only matches the HEAD HTTP method.

func (*Mux) NewSubMux

func (m *Mux) NewSubMux(p string) *Mux

NewSubMux returns a new mux mounted at the given pattern p.

func (*Mux) Options

func (m *Mux) Options(p string, h Handler)

Options registers a route that only matches the OPTIONS HTTP method.

func (*Mux) Patch

func (m *Mux) Patch(p string, h Handler)

Patch registers a route that only matches the PATCH HTTP method.

func (*Mux) Post

func (m *Mux) Post(p string, h Handler)

Post registers a route that only matches the POST HTTP method.

func (*Mux) Put

func (m *Mux) Put(p string, h Handler)

Put registers a route that only matches the PUT HTTP method.

func (*Mux) SetErrorHandler

func (m *Mux) SetErrorHandler(h http.Handler)

SetErrorHandler sets the http.Handler to delegate to when errors are returned.

type Renderable

type Renderable interface {
	Render(view interface{}) ([]byte, error)
}

Renderable represents the ability to render HTML templates.

type UploadForm

type UploadForm interface {
	// MaxUploadSize returns the maximum file upload size in bytes.
	MaxUploadSize() int64
}

UploadForm represents a form with a maximum file upload size.

type Viewable

type Viewable interface{}

Viewable represents a view. To provide an expressive API, this type is an alias for interface{} that is named for documentation.

Jump to

Keyboard shortcuts

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