Documentation
¶
Index ¶
- Constants
- type DumbRouter
- func (dumbRouter *DumbRouter) AddFunctionMapping(funcURL string, function func(req *http.Request, res http.ResponseWriter))
- func (dumbRouter *DumbRouter) CanRoute(routeURL *url.URL) bool
- func (dumbRouter *DumbRouter) GetPriority() int
- func (dumbRouter *DumbRouter) RemoveFunctionMapping(funcURL string)
- func (dumbRouter *DumbRouter) Route(req *http.Request, res http.ResponseWriter) bool
- func (dumbRouter *DumbRouter) SetPriority(pri int)
- type MethodRouter
- func (mrouter *MethodRouter) CanRoute(routeURL *url.URL) bool
- func (mrouter *MethodRouter) GetMethodParameter() string
- func (mrouter *MethodRouter) GetPriority() int
- func (mrouter *MethodRouter) GetTarget() interface{}
- func (mrouter *MethodRouter) GetURL() interface{}
- func (mrouter *MethodRouter) Route(req *http.Request, res http.ResponseWriter) bool
- func (mrouter *MethodRouter) SetMethodParameter(methodParam string)
- func (mrouter *MethodRouter) SetPriority(priority int)
- func (mrouter *MethodRouter) SetTarget(target interface{})
- func (mrouter *MethodRouter) SetURL(URL string)
- type Router
- type RoutingManager
- func (manager *RoutingManager) AddNormalRouter(router Router)
- func (manager *RoutingManager) AddPostRouter(router Router)
- func (manager *RoutingManager) AddPreRouter(router Router)
- func (manager *RoutingManager) AddRouter(router Router, routerType int)
- func (manager *RoutingManager) RouteRequest(req *http.Request, res http.ResponseWriter) error
Constants ¶
const ( //PreRouter is a router that occures before normal and post routers PreRouter = iota //NormalRouter is a router that occures after PreRouters but before PostRouters NormalRouter //PostRouter is a router that occures after all Pre and Normal routers. PostRouter )
const (
//DefaultRouterPriority is the default router priority, most routers should use this.
DefaultRouterPriority = 0
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DumbRouter ¶
type DumbRouter struct {
// contains filtered or unexported fields
}
DumbRouter routes http requests to end points based on a supplied url -> function map.
func (*DumbRouter) AddFunctionMapping ¶
func (dumbRouter *DumbRouter) AddFunctionMapping(funcURL string, function func(req *http.Request, res http.ResponseWriter))
AddFunctionMapping adds a new url -> function mapping to the router
func (*DumbRouter) CanRoute ¶
func (dumbRouter *DumbRouter) CanRoute(routeURL *url.URL) bool
CanRoute returns true if the url-function map has an entry for the url
func (*DumbRouter) GetPriority ¶
func (dumbRouter *DumbRouter) GetPriority() int
GetPriority returns this routers priority
func (*DumbRouter) RemoveFunctionMapping ¶
func (dumbRouter *DumbRouter) RemoveFunctionMapping(funcURL string)
RemoveFunctionMapping removes the function mapping for funcURL
func (*DumbRouter) Route ¶
func (dumbRouter *DumbRouter) Route(req *http.Request, res http.ResponseWriter) bool
Route calls the function associated with the request url
func (*DumbRouter) SetPriority ¶
func (dumbRouter *DumbRouter) SetPriority(pri int)
SetPriority sets the priority of this router.
type MethodRouter ¶
type MethodRouter struct { URL string // contains filtered or unexported fields }
MethodRouter routes requests to methods on a receiver interface (target). The method to which the request is routed is selected via a http parameter "method".
func NewMethodRouter ¶
func NewMethodRouter(target interface{}, targetURL string) *MethodRouter
NewMethodRouter constructs a new method router on the target struct at the given url.
func (*MethodRouter) CanRoute ¶
func (mrouter *MethodRouter) CanRoute(routeURL *url.URL) bool
CanRoute checks if the url is exactly the same as the routers url
func (*MethodRouter) GetMethodParameter ¶
func (mrouter *MethodRouter) GetMethodParameter() string
GetMethodParameter returns the method parameter name which indicates what method to call on the router target.
func (*MethodRouter) GetPriority ¶
func (mrouter *MethodRouter) GetPriority() int
GetPriority returns routers priority setting
func (*MethodRouter) GetTarget ¶
func (mrouter *MethodRouter) GetTarget() interface{}
GetTarget returns the target interface of the method router
func (*MethodRouter) GetURL ¶
func (mrouter *MethodRouter) GetURL() interface{}
GetURL returns the URL of this method router
func (*MethodRouter) Route ¶
func (mrouter *MethodRouter) Route(req *http.Request, res http.ResponseWriter) bool
Route routes the incoming request to the requested method of the target class
func (*MethodRouter) SetMethodParameter ¶
func (mrouter *MethodRouter) SetMethodParameter(methodParam string)
SetMethodParameter sets the method parameter name which indicates what method to call on the router target.
func (*MethodRouter) SetPriority ¶
func (mrouter *MethodRouter) SetPriority(priority int)
SetPriority sets the routers priority
func (*MethodRouter) SetTarget ¶
func (mrouter *MethodRouter) SetTarget(target interface{})
SetTarget sets the target interface of the method router
func (*MethodRouter) SetURL ¶
func (mrouter *MethodRouter) SetURL(URL string)
SetURL sets the URL of this method router
type Router ¶
type Router interface { /* Route routes a request via this routers rules. if the return value is false the request will not be propagated down the priority stack */ Route(req *http.Request, res http.ResponseWriter) bool // CanRoute returns true if the router can / wants to route this url. CanRoute(routeURL *url.URL) bool /* GetPriority gets this Routers priority (0 is highest priority). Higher priority routers run before lower priority routers */ GetPriority() int }
Router routes http requests to end points based on application logic.
type RoutingManager ¶
type RoutingManager struct {
// contains filtered or unexported fields
}
RoutingManager manages routers and routing operation. simply add routers to the manager then feed in http requests and the manager will pass the message on to the correct routers.
func NewRoutingManager ¶
func NewRoutingManager() *RoutingManager
NewRoutingManager creates a new routing Manager.
func (*RoutingManager) AddNormalRouter ¶
func (manager *RoutingManager) AddNormalRouter(router Router)
AddNormalRouter adds a normal router to the manager. A normal router, is a router that occures after PreRouters but before PostRouters.
func (*RoutingManager) AddPostRouter ¶
func (manager *RoutingManager) AddPostRouter(router Router)
AddPostRouter adds a post router to the manager. A post router, is a router that occures affter all Pre and Normal routers.
func (*RoutingManager) AddPreRouter ¶
func (manager *RoutingManager) AddPreRouter(router Router)
AddPreRouter adds a pre router to the manager. A pre router, is a router that occures before normal and post routers.
func (*RoutingManager) AddRouter ¶
func (manager *RoutingManager) AddRouter(router Router, routerType int)
AddRouter adds a router to the manager with the given router type.
func (*RoutingManager) RouteRequest ¶
func (manager *RoutingManager) RouteRequest(req *http.Request, res http.ResponseWriter) error
RouteRequest routes an http request through the registered routers