router

package
v2.0.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2017 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenFor

func ListenFor(hash bool, pattern string, fx func(PushEvent), fail func(PushEvent))

ListenFor takes the giving pattern, matches it against changes provided by the current PathObserver, if the full URL(i.e Path+Hash) matches then fires the provided function.

func ReadBody

func ReadBody(res *http.Response) ([]byte, error)

ReadBody returns the body of the giving response.

func URIMatcher

func URIMatcher(path string) pattern.URIMatcher

URIMatcher returns a new uri matcher if it has not being already creatd.

func WrapHandler

func WrapHandler(fx func()) func(PushEvent)

WrapHandler returns a function of type PathHandler by wrapping the provided no argument function in one.

func WrapParams

func WrapParams(params Params) string

WrapParams transforms the params map into a string of &key=value pair.

Types

type BasicHTTPHandler

type BasicHTTPHandler interface {
	ServeHTTP(http.ResponseWriter, *http.Request) error
}

BasicHTTPHandler defines a request interface which defines a type which will be used to service a http request.

type ErrorHandler

type ErrorHandler struct {
	Handler BasicHTTPHandler
}

ErrorHandler defines a new HTTPHandler which is used to service a request and respond to a giving error that occurs.

func (ErrorHandler) ServeHTTP

func (e ErrorHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP services the incoming request to the underline Handler supplied for the basic handler.

type HTTPCacheHandler

type HTTPCacheHandler interface {
	ServeHTTP(http.ResponseWriter, *http.Request, cache.Cache)
}

HTTPCacheHandler defines a handler which implements a type which allows a handler to have access to a current request and response with the underline cache being used.

type HTTPHandler

type HTTPHandler interface {
	ServeHTTP(http.ResponseWriter, *http.Request)
}

HTTPHandler defines a request interface which defines a type which will be used to service a http request.

func NewErrorHandler

func NewErrorHandler(bh BasicHTTPHandler) HTTPHandler

NewErrorHandler returns a new instance of the HTTPHandler which is used to service a request and respond to a giving error that occurs.

type HandleMux

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

HandleMux defines a structure which handles the variaties in the supported request handlers of the router package and encapsulates the needed behaviour calls.

func NewHandleMux

func NewHandleMux(handler interface{}) HandleMux

NewHandleMux returns a new instance of a HandleMux.

func (HandleMux) Match

func (m HandleMux) Match(path string) (string, HTTPCacheHandler, error)

Match examines the path and returns a new path, a Mux to handle the request else returns an error if one is not found.

func (HandleMux) ServeHTTP

func (m HandleMux) ServeHTTP(w http.ResponseWriter, r *http.Request, c cache.Cache)

ServeAndCache attempts to service request with either the cache or normal handler found within itself.

type Handler

type Handler func(PushEvent)

Handler defines a function type for a Resolver subcriber.

type Multiplexer

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

Multiplexer defines a struct which manages giving set of Mux and adequates calls the first to match a giving request about a incoming request.

func NewMultiplexer

func NewMultiplexer(mx ...Mux) Multiplexer

NewMultiplexer returns a new instance of a Multiplexer.

func (Multiplexer) Match

func (m Multiplexer) Match(path string) (string, HTTPCacheHandler, error)

Match examines the path and returns a new path, a Mux to handle the request else returns an error if one is not found.

type Mux

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

Mux defines a structure which giving a Matcher and a handler which implements either the HTTPCacheHandler/BasicHandler/HTTPHandler and also optionally the PreprocessorHandler, where request being serviced will receive a new path when called and will be used to define, which part an external service will use to service a incoming relative path request. Below is demonstrated a scenario where Mux can be used for to handle request for specific namespace. Scenrio:

Mux has URI Matcher for github/*

When:

Mux receives request for github/gu-io/buba

If Mux has Preprocessor to to transform path to github.com/path:

Then: Path returned is github.com/gu-io/buba

If Mux has No Preprocessor

Then: Path returned is gu-io/buba.

func NewMux

func NewMux(namespace string, handler interface{}) Mux

NewMux returns a new instance of a mux.

func (*Mux) Match

func (m *Mux) Match(path string) (string, HTTPCacheHandler, error)

Match validates that the giving Mux matches the wanted path and extracts the real path from the provided path, returning the true/false if it matched the path.

type NilServer

type NilServer struct{}

NilServer defines a empty struct implementing the http.Handler interface.

func (NilServer) ServeHTTP

func (NilServer) ServeHTTP(_ http.ResponseWriter, _ *http.Request)

ServeHTTP implements the http.Handler inface ServeHTTP method.

type Params

type Params map[string]string

Params defines a map type of key-value pairs to be sent as query parameters.

type PreprocessHandler

type PreprocessHandler interface {
	Preprocess(string) string
}

PreprocessHandler exposes a type which implements both the http.Handler and a method which pre-processes giving routes for use in a request.

type PushDirectiveEvent

type PushDirectiveEvent struct {
	To string
}

PushDirectiveEvent defines a event which is used to declare the switching of the route to another path provided.

type PushEvent

type PushEvent struct {
	Host   string
	Hash   string
	Path   string
	Rem    string
	To     string
	From   string
	Params map[string]string
}

PushEvent represent the current path and hash values.

@notification:event

func NewPushEvent

func NewPushEvent(path string, useHash bool) (PushEvent, error)

NewPushEvent returns PushEvent based on the path string provided.

func UseLocation

func UseLocation(path string) PushEvent

UseLocation returns the current Path associated with the provided path. Using the complete path has the Remaining path value.

func UseLocationHash

func UseLocationHash(path string) PushEvent

UseLocationHash returns the current Path associated with the provided path. Using the hash path has the Remaining path value.

func (PushEvent) String

func (p PushEvent) String() string

String returns the hash and path.

type PushEventHandler

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

PushEventHandler defines a structure type which implements the PushEventSubscriber interface and the EventDistributor interface.

func NewPushEventHandler

func NewPushEventHandler(fn func(PushEvent)) *PushEventHandler

NewPushEventHandler returns a new instance of a PushEventHandler.

func (*PushEventHandler) Handle

func (sn *PushEventHandler) Handle(receive interface{})

Handle takes the giving value and asserts the expected value to match the PushEvent type then passes it to the Receive method.

func (*PushEventHandler) Receive

func (sn *PushEventHandler) Receive(elem PushEvent)

Receive takes the giving value and execute it against the underline handler.

type PushEventNotification

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

PushEventNotification defines a structure type which must be used to receive PushEvent type has a event.

func NewPushEventNotification

func NewPushEventNotification() *PushEventNotification

NewPushEventNotification returns a new instance of NewPushEventNotification.

func NewPushEventNotificationWith

func NewPushEventNotificationWith(validation func(PushEvent) bool) *PushEventNotification

NewPushEventNotificationWith returns a new instance of PushEventNotification.

func (*PushEventNotification) Handle

func (sn *PushEventNotification) Handle(elem interface{})

Handle takes the giving value and asserts the expected value to be of the type and pass on to it's underline subscribers else ignoring the event.

func (*PushEventNotification) Notify

Notify adds the given subscriber into the notification list and will await an update of a new event of the given PushEvent type.

func (*PushEventNotification) UnNotify

func (sn *PushEventNotification) UnNotify(sub PushEventSubscriber)

UnNotify removes the given subscriber from the notification's list if found from future events.

type PushEventSubscriber

type PushEventSubscriber interface {
	Receive(PushEvent)
}

PushEventSubscriber defines a interface that which is used to subscribe specifically for events PushEvent type.

type Resolvable

type Resolvable interface {
	Resolve(PushEvent)
}

Resolvable defines an interface for a resolvable type object.

type ResolveMorpher

type ResolveMorpher interface {
	Resolver
	trees.Morpher
}

ResolveMorpher defines an interface for a Resolver which can morph a trees.Markup state.

type Resolver

type Resolver interface {
	Resolvable

	Flush()
	Pattern() string
	Only(string, ...trees.SwitchMorpher) ResolveMorpher
	Register(Resolver)
	Done(Handler) Resolver
	Failed(Handler) Resolver
	Test(string) (map[string]string, string, bool)
}

Resolver defines an interface for a type that resolves a provided instance of a dispatch.PushEvent.

func ListenAndResolve

func ListenAndResolve(pattern string, fx func(PushEvent), fail func(PushEvent)) Resolver

ListenAndResolve takes the giving pattern, matches it against changes provided by the current PathObserver, if the full URL(i.e Path+Hash) matches then fires the provided function.

func NewResolver

func NewResolver(path string) Resolver

NewResolver returns a new instance of a structure that matches the Resolver interface.

type RouteApplier

RouteApplier defines a interface which composes trees Applier, Morpher and the Resolver to handle routing over against a tree markup.

type RouteManager

type RouteManager struct {
	Levels map[string]RouteApplier
}

RouteManager defines a router which handles creation and registering of a set of level connecting routes

func NewRouteManager

func NewRouteManager() *RouteManager

NewRouteManager returns a new instance of RouteManager.

func (*RouteManager) L

func (r *RouteManager) L(path string) RouteApplier

L returns a RouteApplier attached to a giving manager which cache and manages the different defined routes.

func (*RouteManager) Level

func (r *RouteManager) Level(path string, morpher trees.SwitchMorpher) RouteApplier

Level creates a new route level using the provided string as the base path for its root router.

type Router

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

Router exposes a struct which describes a multi-handler of request where it

func NewRouter

func NewRouter(handler interface{}, cache cache.Cache) *Router

NewRouter returns a new instance of a Router.

func (*Router) Cache

func (r *Router) Cache() cache.Cache

Cache returns the internal cache used by the router.

func (*Router) Delete

func (r *Router) Delete(path string, params Params) (*http.Response, error)

Delete retrieves the giving path and returns the response expected using a DELETE method.

func (*Router) Do

func (r *Router) Do(method string, path string, params Params, body io.ReadCloser) (*http.Response, error)

Do performs the giving requests for a giving path with the provided body and returns the response for that method.

func (*Router) Get

func (r *Router) Get(path string, params Params) (*http.Response, error)

Get retrieves the giving path and returns the response expected using a GET method.

func (*Router) Head

func (r *Router) Head(path string, params Params) (*http.Response, error)

Head retrieves the giving path and returns the response expected using a HEAD method.

func (*Router) Options

func (r *Router) Options(path string, params Params) (*http.Response, error)

Options retrieves the giving path and returns the response expected using a OPTIONS method.

func (*Router) Patch

func (r *Router) Patch(path string, params Params, body io.ReadCloser) (*http.Response, error)

Patch retrieves the giving path and returns the response expected using a PATCH method.

func (*Router) Post

func (r *Router) Post(path string, params Params, body io.ReadCloser) (*http.Response, error)

Post retrieves the giving path and returns the response expected using a POST method.

func (*Router) Put

func (r *Router) Put(path string, params Params, body io.ReadCloser) (*http.Response, error)

Put retrieves the giving path and returns the response expected using a PUT method.

type Routing

type Routing struct {
	Resolver
	// contains filtered or unexported fields
}

Routing defines a Resolve structure that allows morphing the output of a markup based on a giving route.

func NewRouting

func NewRouting(path string, morpher trees.SwitchMorpher) *Routing

NewRouting returns a new instance of a Routing struct.

func (*Routing) Apply

func (r *Routing) Apply(mr *trees.Markup)

Apply adds this routing as a morpher into the provided markup.

func (*Routing) Morph

func (r *Routing) Morph(mr *trees.Markup) *trees.Markup

Morph implements the Morpher interface providing the routing with the ability. It lets routing morph markup passed into it.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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