dingo

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

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

Go to latest
Published: May 9, 2014 License: BSD-2-Clause-Views Imports: 10 Imported by: 0

Documentation

Overview

Package dingo is a simple wrapper around net/http providing very simple routing, with RegEx patterns, and views (templates).

Index

Constants

View Source
const (
	VERSION string = "0.1.15"
)

Variables

This section is empty.

Functions

func HTTPListener

func HTTPListener(ip string, port int) (net.Listener, error)

HTTPListener returns a new net.Listener for the given ip/port

func IsCanonical

func IsCanonical(p string) (string, bool)

IsCanonical returns wether the given path is canonical.

func SOCKListener

func SOCKListener(sockFile string, mode os.FileMode) (net.Listener, error)

SOCKListener returns a new unix sock listener.

func TLSListener

func TLSListener(ip string, port int, certFile, keyFile string) (net.Listener, error)

TLSListener returns a new net.Listener for the given ip/port and cert

Types

type Context

type Context struct {
	*http.Request
	Response  http.ResponseWriter
	RouteData map[string]string
}

Context holds both the request and response objects, along with route-data, and is passed to handlers.

func NewContext

func NewContext(response http.ResponseWriter, request *http.Request) Context

NewContext creates, and returns, a new Context

func (*Context) HttpError

func (c *Context) HttpError(status int, msgs ...string)

HttpError issues the given http error (status) and writes any provided msgs. The ErrorHandler is invoked when it has been set and there are no provided msgs.

func (*Context) Redirect

func (c *Context) Redirect(path string)

Redirect issues a redirect to the response.

func (*Context) RedirectPerm

func (c *Context) RedirectPerm(path string)

RedirectPerm issues a permanent redirect to the response.

type Error

type Error func(ctx Context, status int) bool

Error func is a handler type called when there is a panic.

var ErrorHandler Error

ErrorHandler is the actual handler invoked upon panic.

type Handler

type Handler func(ctx Context)

Handler is a func type called when a matching route is found.

type NewIRoute

type NewIRoute func(path string, h interface{}) Route

NewIRoute returns a new route for the given path and handler.

type Route

type Route interface {
	Path() string
	IsCanonical() bool
	Matches(path string) bool
	Execute(ctx Context)
}

Route is the handling object when a request matches.

func NewRRoute

func NewRRoute(re string, handler interface{}) Route

NewRRoute returns a new RegEx route for the given path/handler.

func NewReRoute

func NewReRoute(re string, handler Handler) Route

NewReRoute returns a new RegEx route for the given path/handler.

func NewSRoute

func NewSRoute(path string, handler Handler) Route

NewSRoute returns a new static route for the given path/handler.

type Router

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

func NewRouter

func NewRouter(s *Server, path string, route NewIRoute) Router

NewRouter returns a router.

func (Router) Connect

func (r Router) Connect(h interface{}) Router

Options adds a route for "CONNECT" method.

func (Router) Delete

func (r Router) Delete(h interface{}) Router

Options adds a route for "DELETE" method.

func (Router) Get

func (r Router) Get(h interface{}) Router

Options adds a route for "GET" method.

func (Router) Options

func (r Router) Options(h interface{}) Router

Options adds a route for "OPTIONS" method.

func (Router) Post

func (r Router) Post(h interface{}) Router

Options adds a route for "POST" method.

func (Router) Put

func (r Router) Put(h interface{}) Router

Options adds a route for "PUT" method.

func (Router) Trace

func (r Router) Trace(h interface{}) Router

Options adds a route for "TRACE" method.

type Routes

type Routes interface {
	Route(url string) (Route, bool)
	Add(route Route)
}

Routes is a collection of Route types.

type Server

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

Server implements http.Handler and routes calls to handlers view a Routes collection.

func New

func New(l net.Listener) Server

New returns a new Server.

func (*Server) RRoute

func (s *Server) RRoute(path string, handler interface{}, methods ...string)

RRoute adds a new RegEx route where the params are passed as params to the given handler.

func (*Server) RRouter

func (s *Server) RRouter(p string) Router

SRouter returns a new Router used to add RegEx routes to the server where the params are passed to the handler.

func (*Server) ReRoute

func (s *Server) ReRoute(path string, handler Handler, methods ...string)

ReRoute adds a new RegEx route.

func (*Server) ReRouter

func (s *Server) ReRouter(p string) Router

SRouter returns a new Router used to add RegEx routes to the server.

func (*Server) Route

func (s *Server) Route(rt Route, methods ...string)

Route adds a route for the given methods.

func (*Server) SRoute

func (s *Server) SRoute(path string, handler Handler, methods ...string)

SRoute adds a new static route.

func (*Server) SRouter

func (s *Server) SRouter(p string) Router

SRouter returns a new Router used to add static routes to the server.

func (*Server) Serve

func (s *Server) Serve()

Serve begins listening for requests

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

http.Handler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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