sleepy

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2014 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GET    = "GET"
	POST   = "POST"
	PUT    = "PUT"
	DELETE = "DELETE"
	HEAD   = "HEAD"
	PATCH  = "PATCH"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

An API manages a group of resources by routing requests to the correct method on a matching resource and marshalling the returned data to JSON for the HTTP response.

You can instantiate multiple APIs on separate ports. Each API will manage its own set of resources.

func NewAPI

func NewAPI() *API

NewAPI allocates and returns a new API.

func (*API) AddResource

func (api *API) AddResource(resource interface{}, paths ...string)

AddResource adds a new resource to an API. The API will route requests that match one of the given paths to the matching HTTP method on the resource.

func (*API) AddResourceWithWrapper

func (api *API) AddResourceWithWrapper(resource interface{}, wrapper func(handler http.HandlerFunc) http.HandlerFunc, paths ...string)

AddResourceWithWrapper behaves exactly like AddResource but wraps the generated handler function with a give wrapper function to allow to hook in Gzip support and similar.

func (*API) Mux

func (api *API) Mux() APIMux

Mux returns the muxer used by an API. If a ServeMux does not yet exist, a new *http.ServeMux will be created and returned.

func (*API) SetMux

func (api *API) SetMux(mux APIMux) error

SetMux sets the muxer to use by an API. A muxer needs to implement the APIMux interface (eg. http.ServeMux).

func (*API) Start

func (api *API) Start(port int) error

Start causes the API to begin serving requests on the given port.

type APIMux

type APIMux interface {
	HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) *mux.Route
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

Interface for arbitrary muxer support (like http.ServeMux).

type DeleteSupported

type DeleteSupported interface {
	Delete(*http.Request) (int, interface{}, http.Header)
}

DeleteSupported is the interface that provides the Delete method a resource must support to receive HTTP DELETEs.

type GetSupported

type GetSupported interface {
	Get(*http.Request) (int, interface{}, http.Header)
}

GetSupported is the interface that provides the Get method a resource must support to receive HTTP GETs.

type HeadSupported

type HeadSupported interface {
	Head(*http.Request) (int, interface{}, http.Header)
}

HeadSupported is the interface that provides the Head method a resource must support to receive HTTP HEADs.

type PatchSupported

type PatchSupported interface {
	Patch(*http.Request) (int, interface{}, http.Header)
}

PatchSupported is the interface that provides the Patch method a resource must support to receive HTTP PATCHs.

type PostSupported

type PostSupported interface {
	Post(*http.Request) (int, interface{}, http.Header)
}

PostSupported is the interface that provides the Post method a resource must support to receive HTTP POSTs.

type PutSupported

type PutSupported interface {
	Put(*http.Request) (int, interface{}, http.Header)
}

PutSupported is the interface that provides the Put method a resource must support to receive HTTP PUTs.

Jump to

Keyboard shortcuts

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