Documentation ¶
Overview ¶
Package httpc implements HTTP request and response helpers.
Index ¶
- Constants
- func Abort(w http.ResponseWriter, code int) error
- func Error(req *http.Request) error
- func NoContent(w http.ResponseWriter) error
- func Param(req *http.Request, name string) string
- func Path(req *http.Request) string
- func Pattern(req *http.Request) *pat.Pattern
- func Query(req *http.Request, name string) string
- func Redirect(w http.ResponseWriter, req *http.Request, path string, code int) error
- func RedirectTo(w http.ResponseWriter, req *http.Request, format string, args ...interface{}) error
- func RemoteAddr(req *http.Request) string
- func Render(w http.ResponseWriter, req *http.Request, view Viewable, code int) error
- func RenderHTML(w http.ResponseWriter, view Renderable, code int) error
- func RenderJSON(w http.ResponseWriter, view Viewable, code int) error
- func RenderPlain(w http.ResponseWriter, view Viewable, code int) error
- func ServeFile(w http.ResponseWriter, req *http.Request, name string) error
- func SetCookie(w http.ResponseWriter, cookie *http.Cookie)
- func Validate(req *http.Request, form Form) error
- func ValidateForm(req *http.Request, form Form) error
- func ValidateJSON(req *http.Request, form Form) error
- func ValidateMultipart(req *http.Request, form Form) error
- type Form
- type Handler
- type Mux
- func (m *Mux) Any(p string, h Handler)
- func (m *Mux) Delete(p string, h Handler)
- func (m *Mux) FileServer(p string, fs http.FileSystem)
- func (m *Mux) Get(p string, h Handler)
- func (m *Mux) Handle(p string, h http.Handler)
- func (m *Mux) Head(p string, h Handler)
- func (m *Mux) NewSubMux(p string) *Mux
- func (m *Mux) Options(p string, h Handler)
- func (m *Mux) Patch(p string, h Handler)
- func (m *Mux) Post(p string, h Handler)
- func (m *Mux) Put(p string, h Handler)
- func (m *Mux) SetErrorHandler(h http.Handler)
- type Renderable
- type UploadForm
- type Viewable
Constants ¶
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 NoContent ¶
func NoContent(w http.ResponseWriter) error
NoContent writes http.StatusNoContent to the header.
func Pattern ¶
Pattern returns the pattern corresponding to the most recently matched pattern, or nil if no pattern was matched.
func Query ¶
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 ¶
Redirect replies to the request with a redirect to path. This is the equivalent to http.Redirect and is here for consistency.
func RedirectTo ¶
RedirectTo replies to the request with a redirect to the application path constructed from the format specifier and args.
func RemoteAddr ¶
RemoteAddr returns a best guess remote address.
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 ¶
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 ¶
Validate decodes, sanitizes and validates the request body and stores the result in to the value pointed to by form.
func ValidateForm ¶
ValidateForm decodes, sanitizes and validates the request body as a form and stores the result in the value pointed to by form.
func ValidateJSON ¶
ValidateJSON decodes, sanitizes and validates the request body as JSON 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 (*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 ¶
Get registers a route that only matches the GET and HEAD HTTP methods. HEAD requests are handled transparently by net/http.
func (*Mux) SetErrorHandler ¶
SetErrorHandler sets the http.Handler to delegate to when errors are returned.
type Renderable ¶
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.