Documentation
¶
Index ¶
- Constants
- Variables
- type InsertOption
- type Mux
- func (m *Mux) AddMatchedRoute(matcher sabuhp.Matcher, response sabuhp.TransportResponse)
- func (m *Mux) AddPre(response sabuhp.Wrapper)
- func (m *Mux) AddPreHttp(response sabuhp.HttpWrapper)
- func (m *Mux) Event(eventName string, handler sabuhp.TransportResponse) sabuhp.Channel
- func (m *Mux) Http(route string, handler sabuhp.Handler, methods ...string)
- func (m *Mux) HttpService(route string, handler sabuhp.TransportResponse, methods ...string)
- func (m *Mux) HttpServiceWithName(eventName string, route string, handler sabuhp.TransportResponse, ...)
- func (m *Mux) Match(msg *sabuhp.Message) bool
- func (m *Mux) RedirectAsPath(route string, methods ...string)
- func (m *Mux) RedirectTo(eventName string, route string, methods ...string)
- func (m *Mux) Routes() []string
- func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (m *Mux) ServeWithMatchers(msg *sabuhp.Message, tr sabuhp.Transport) sabuhp.MessageErr
- func (m *Mux) Service(eventName string, route string, handler sabuhp.TransportResponse, ...) sabuhp.Channel
- type MuxConfig
- type Node
- type NodeKeysSorter
- type ParamsSetter
- type Trie
- func (t *Trie) Autocomplete(prefix string, sorter NodeKeysSorter) (list []string)
- func (t *Trie) HasPrefix(prefix string) bool
- func (t *Trie) Insert(pattern string, options ...InsertOption)
- func (t *Trie) Parents(prefix string) (parents []*Node)
- func (t *Trie) Search(q string, params ParamsSetter) *Node
- func (t *Trie) SearchPrefix(prefix string) *Node
Constants ¶
const ( // ParamStart is the character, as a string, which a path pattern starts to define its named parameter. ParamStart = ":" // WildcardParamStart is the character, as a string, // which a path pattern starts to define its named parameter for wildcards. // It allows everything else after that path prefix // but the Trie checks for static paths and named parameters before that in order // to support everything that other implementations do not, // and if nothing else found then it tries to find the closest wildcard path(super and unique). WildcardParamStart = "*" )
Variables ¶
var DefaultKeysSorter = func(list []string) func(i, j int) bool { return func(i, j int) bool { return len(strings.Split(list[i], pathSep)) < len(strings.Split(list[j], pathSep)) } }
DefaultKeysSorter sorts as: first the "key (the path)" with the lowest number of slashes.
Functions ¶
This section is empty.
Types ¶
type InsertOption ¶
type InsertOption func(*Node)
InsertOption is just a function which accepts a pointer to a Node which can alt its `sabuhp.Handler`, `Tag` and `Data` fields.
See `WithTransportResponse`, `WithTag` and `WithData`.
func WithData ¶
func WithData(data interface{}) InsertOption
WithData sets the node's optionally `Data` field.
func WithHandler ¶
func WithHandler(handler sabuhp.Handler) InsertOption
WithHandler sets the node's `Handler` field (useful for HTTP).
func WithTag ¶
func WithTag(tag string) InsertOption
WithTag sets the node's `Tag` field (may be useful for HTTP).
func WithTransportResponse ¶
func WithTransportResponse(handler sabuhp.Handler) InsertOption
WithTransportResponse sets the node's `Handler` field (useful for HTTP).
type Mux ¶
Mux is Request multiplexer. It matches an event name or http url pattern to a specific TransportHandler which will be registered to the provided transport for handling specific events.
func (*Mux) AddMatchedRoute ¶
func (m *Mux) AddMatchedRoute(matcher sabuhp.Matcher, response sabuhp.TransportResponse)
AddMatchedRoute adds a priority route which takes priority to all other routes local to the multiplexer. If a message is matched by said router then that Handler will handle said message accordingly.
func (*Mux) AddPre ¶
AddPre adds a response.Handler which will act as a middleware wrapper for all route's response before the target handler.
func (*Mux) AddPreHttp ¶
func (m *Mux) AddPreHttp(response sabuhp.HttpWrapper)
AddPreHttp adds a http wrapper which will act as a middleware wrapper for all route's response before the target handler.
func (*Mux) Event ¶ added in v0.2.6
Event registers handlers for a giving event returning it's channel.
Understand that closing the channel does not close the http endpoint.
func (*Mux) HttpService ¶
func (m *Mux) HttpService(route string, handler sabuhp.TransportResponse, methods ...string)
HttpService registers handlers for giving only through the http router it does not add said handler into the event manager. This exists to allow http requests to be treated as message event.
The event name will be the route of the http request path.
Understand that closing the channel does not close the http endpoint.
func (*Mux) HttpServiceWithName ¶
func (m *Mux) HttpServiceWithName(eventName string, route string, handler sabuhp.TransportResponse, methods ...string)
HttpServiceWithName registers handlers for giving only through the http router it does not add said handler into the event manager. This exists to allow http requests to be treated as message event.
The event name will be the route of the http request path.
Understand that closing the channel does not close the http endpoint.
func (*Mux) Match ¶
Match implements the Matcher interface.
Allow a mux to be used as a matcher and handler elsewhere.
func (*Mux) RedirectAsPath ¶
RedirectAsPath redirects all requests from giving http route into the pubsub using path as event name .
Understand that closing the channel does not close the http endpoint.
func (*Mux) RedirectTo ¶
RedirectTo redirects all requests giving http route into the pubsub using provided configuration on the HttpToEventService.
Understand that closing the channel does not close the http endpoint.
func (*Mux) ServeWithMatchers ¶ added in v0.2.6
type MuxConfig ¶
type MuxConfig struct { RootPath string Logger sabuhp.Logger NotFound sabuhp.Handler Manager *managers.Manager Ctx context.Context Transposer sabuhp.Transposer Translator sabuhp.Translator Headers sabuhp.HeaderModifications }
type Node ¶
type Node struct { // insert main data relative to http and a tag for things like route names. Handler sabuhp.Handler Tag string // other insert data. Data interface{} // contains filtered or unexported fields }
Node is the trie's node which path patterns with their data like an HTTP handler are saved to. See `Trie` too.
func (*Node) Keys ¶
func (n *Node) Keys(sorter NodeKeysSorter) (list []string)
Keys returns this node's key (if it's a final path segment) and its children's node's key. The "sorter" can be optionally used to sort the result.
type NodeKeysSorter ¶
NodeKeysSorter is the type definition for the sorting logic that caller can pass on `GetKeys` and `Autocomplete`.
type ParamsSetter ¶
ParamsSetter is the interface which should be implemented by the params writer for `Search` in order to store the found named path parameters, if any.
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
Trie contains the main logic for adding and searching nodes for path segments. It supports wildcard and named path parameters. Trie supports very coblex and useful path patterns for routes. The Trie checks for static paths(path without : or *) and named parameters before that in order to support everything that other implementations do not, and if nothing else found then it tries to find the closest wildcard path(super and unique).
func NewTrie ¶
func NewTrie() *Trie
NewTrie returns a new, empty Trie. It is only useful for end-developers that want to design their own mux/router based on my trie implementation.
See `Trie`
func (*Trie) Autocomplete ¶
func (t *Trie) Autocomplete(prefix string, sorter NodeKeysSorter) (list []string)
Autocomplete returns the keys that starts with "prefix", this is useful for custom search-engines built on top of my trie implementation.
func (*Trie) Insert ¶
func (t *Trie) Insert(pattern string, options ...InsertOption)
Insert adds a node to the trie.
func (*Trie) Search ¶
func (t *Trie) Search(q string, params ParamsSetter) *Node
Search is the most important part of the Trie. It will try to find the responsible node for a specific query (or a request path for HTTP endpoints).
Search supports searching for static paths(path without : or *) and paths that contain named parameters or wildcards. Priority as: 1. static paths 2. named parameters with ":" 3. wildcards 4. closest wildcard if not found, if any 5. rootPath wildcard
func (*Trie) SearchPrefix ¶
SearchPrefix returns the last node which holds the key which starts with "prefix".