http

package
v1.0.1-0...-3bd088d Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

README

http

Package http providers utilities for http.

Documentation

Overview

Package http providers utilities for http.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware interface {
	// Wrap waprs the handler.
	Wrap(http.Handler) http.Handler
}

Middleware represents a wrapper for http handler.

type MiddlewareFunc

type MiddlewareFunc func(http.Handler) http.Handler

MiddlewareFunc an adapter to allow the use of ordinary functions as middlewares.

func (MiddlewareFunc) Wrap

Wrap warps the m to http.Handler. Wrap implements Middleware interface.

type Request

type Request struct {
	*http.Request
}

Request represents a wrapper for http request. It stores the parameters directly in the http.Request by mutating the request.Body.

func NewRequest

func NewRequest(r *http.Request) *Request

NewRequest returns a new request.

func (Request) IPAddress

func (r Request) IPAddress() string

IPAddress returns the client ip address. It resolves X-Real-IP and X-Forwarded-For in header.

func (Request) Method

func (r Request) Method() string

Method returns the http method. It resolves X-HTTP-Method-Override in header.

func (*Request) Parameter

func (r *Request) Parameter(key interface{}) interface{}

Parameter get the parameter value.

func (*Request) Parameters

func (r *Request) Parameters() map[interface{}]interface{}

Parameters returns the all parameters.

func (Request) ReadJSON

func (r Request) ReadJSON(obj interface{}) error

ReadJSON reads body as JSON to obj.

func (Request) ReadString

func (r Request) ReadString() (string, error)

ReadString reads body as string.

func (Request) ReadXML

func (r Request) ReadXML(obj interface{}) error

ReadXML reads body as XML to obj.

func (*Request) SetParameter

func (r *Request) SetParameter(key interface{}, value interface{})

SetParameter sets the parameter value.

type ResponseWriter

type ResponseWriter struct {
	http.ResponseWriter
}

ResponseWriter represents a wrapper for http.ResponseWriter.

func NewResponseWriter

func NewResponseWriter(rw http.ResponseWriter) *ResponseWriter

NewResponseWriter returns a new response writer.

func (ResponseWriter) WriteJSON

func (r ResponseWriter) WriteJSON(obj interface{}) (int, error)

WriteJSON writes the obj as JSON into the response body. It sets the Content-Type as "application/json".

func (ResponseWriter) WriteString

func (r ResponseWriter) WriteString(str string) (int, error)

WriteString writes the str into the response body. It sets the Content-Type as "text/plain".

func (ResponseWriter) WriteXML

func (r ResponseWriter) WriteXML(obj interface{}) (int, error)

WriteXML writes the obj as XML into the response body. It sets the Content-Type as "application/xml".

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router represents a HTTP router.

func MustNewRouter

func MustNewRouter(mux ServeMux) *Router

MustNewRouter is like as NewRouter but panic if error happens.

func NewRouter

func NewRouter(mux ServeMux) (*Router, error)

NewRouter returns a new router.

func (*Router) Delete

func (r *Router) Delete(path string, handler http.Handler, middlewares ...Middleware)

Delete is short for Handle (handle DELETE request).

func (*Router) Get

func (r *Router) Get(path string, handler http.Handler, middlewares ...Middleware)

Get is short for Handle (handle GET request).

func (*Router) Handle

func (r *Router) Handle(method string, path string, handler http.Handler, middlewares ...Middleware)

Handle registers the handler for handling request matches given method and path pattern.

func (*Router) Head

func (r *Router) Head(path string, handler http.Handler, middlewares ...Middleware)

Head is short for Handle (handle HEAD request).

func (*Router) Options

func (r *Router) Options(path string, handler http.Handler, middlewares ...Middleware)

Options is short for Handle (handle OPTIONS request).

func (*Router) Patch

func (r *Router) Patch(path string, handler http.Handler, middlewares ...Middleware)

Patch is short for Handle (handle PATCH request).

func (*Router) Post

func (r *Router) Post(path string, handler http.Handler, middlewares ...Middleware)

Post is short for Handle (handle POST request).

func (*Router) Put

func (r *Router) Put(path string, handler http.Handler, middlewares ...Middleware)

Put is short for Handle (handle PUT request).

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP dispatches the request to the handler whose pattern most closely matches the request URL. It implements http.Handler interface.

func (*Router) Use

func (r *Router) Use(middleware Middleware) *Router

Use uses the given middleware for wrapping all handlers.

type ServeMux

type ServeMux interface {
	http.Handler

	// Handle registers the handler for the given pattern (method and path).
	Handle(method, path string, handler http.Handler)
}

ServeMux represents a HTTP request multiplexer.

Jump to

Keyboard shortcuts

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