ws

package
v0.0.0-...-301f747 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2015 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package ws profides utilities to create webservices. It is a lightweight framework around the stardard net/http and the httprouter libraries. It uses go.net/context to store values for the lifetime of a request. The design of the framework is based on this excellent article on web frameworks in go. http://nicolasmerouze.com/build-web-framework-golang/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Params

func Params(ctx context.Context) httprouter.Params

Params returns the route parameters from the context

Types

type Handler

type Handler interface {
	ServeHTTP(context.Context, http.ResponseWriter, *http.Request)
}

Handler is an interface for processing an http request. Based on the standard http lib but with an additional context object.

type HandlerFunc

type HandlerFunc func(context.Context, http.ResponseWriter, *http.Request)

HandlerFunc defines a handler function for a request.

func (HandlerFunc) ServeHTTP

func (f HandlerFunc) ServeHTTP(ctx context.Context, w http.ResponseWriter, r *http.Request)

ServeHTTP allows the HandlerFunc to be used as an handler.

type Middleware

type Middleware func(Handler) Handler

Middleware is a function that implements additional functionnality for a handler.

type MiddlewareGroup

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

MiddlewareGroup allows simple chaining of middlewares. Based on alice (https://github.com/justinas/alice).

func NewMiddlewareGroup

func NewMiddlewareGroup(handlers ...Middleware) MiddlewareGroup

NewMiddlewareGroup creates a new middleware group.

func (MiddlewareGroup) Append

func (g MiddlewareGroup) Append(handlers ...Middleware) MiddlewareGroup

Append creates a new middleware group from an existing group.

func (MiddlewareGroup) Then

func (g MiddlewareGroup) Then(handlerFunc HandlerFunc) Handler

Then returns a handler that executes the middleware chain then calls handler.

type Router

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

Router handles routes for the application. It is a simple wrapper around the httprouter lib.

func NewRouter

func NewRouter() *Router

NewRouter creates a new router object.

func (*Router) DELETE

func (r *Router) DELETE(path string, handle Handler)

DELETE registers a DELETE route handler.

func (*Router) GET

func (r *Router) GET(path string, handle Handler)

GET registers a GET route handler.

func (*Router) POST

func (r *Router) POST(path string, handle Handler)

POST registers a POST route handler.

func (*Router) PUT

func (r *Router) PUT(path string, handle Handler)

PUT registers a PUT route handler.

func (*Router) ServeFiles

func (r *Router) ServeFiles(path string, root http.FileSystem)

ServeFiles serves files from the filesystem.

func (*Router) ServeHTTP

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

Jump to

Keyboard shortcuts

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