parent
6005a964ba
commit
7b1f83f6b7
17
router.go
17
router.go
|
@ -98,7 +98,7 @@ type Handler interface {
|
||||||
type Route struct {
|
type Route struct {
|
||||||
handler Handler
|
handler Handler
|
||||||
// Matchers are used to "specialize" routes and focus on specific packet features
|
// Matchers are used to "specialize" routes and focus on specific packet features
|
||||||
matchers []matcher
|
matchers []Matcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Route) Handler(handler Handler) *Route {
|
func (r *Route) Handler(handler Handler) *Route {
|
||||||
|
@ -122,8 +122,8 @@ func (r *Route) HandlerFunc(f HandlerFunc) *Route {
|
||||||
return r.Handler(f)
|
return r.Handler(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// addMatcher adds a matcher to the route
|
// AddMatcher adds a matcher to the route
|
||||||
func (r *Route) addMatcher(m matcher) *Route {
|
func (r *Route) AddMatcher(m Matcher) *Route {
|
||||||
r.matchers = append(r.matchers, m)
|
r.matchers = append(r.matchers, m)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ func (n nameMatcher) Match(p stanza.Packet, match *RouteMatch) bool {
|
||||||
// It matches on the Local part of the xml.Name
|
// It matches on the Local part of the xml.Name
|
||||||
func (r *Route) Packet(name string) *Route {
|
func (r *Route) Packet(name string) *Route {
|
||||||
name = strings.ToLower(name)
|
name = strings.ToLower(name)
|
||||||
return r.addMatcher(nameMatcher(name))
|
return r.AddMatcher(nameMatcher(name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------
|
// -------------------------
|
||||||
|
@ -204,7 +204,7 @@ func (r *Route) StanzaType(types ...string) *Route {
|
||||||
for k, v := range types {
|
for k, v := range types {
|
||||||
types[k] = strings.ToLower(v)
|
types[k] = strings.ToLower(v)
|
||||||
}
|
}
|
||||||
return r.addMatcher(nsTypeMatcher(types))
|
return r.AddMatcher(nsTypeMatcher(types))
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------
|
// -------------------------
|
||||||
|
@ -229,14 +229,15 @@ func (r *Route) IQNamespaces(namespaces ...string) *Route {
|
||||||
for k, v := range namespaces {
|
for k, v := range namespaces {
|
||||||
namespaces[k] = strings.ToLower(v)
|
namespaces[k] = strings.ToLower(v)
|
||||||
}
|
}
|
||||||
return r.addMatcher(nsIQMatcher(namespaces))
|
return r.AddMatcher(nsIQMatcher(namespaces))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Matchers
|
// Matchers
|
||||||
|
|
||||||
// Matchers are used to "specialize" routes and focus on specific packet features
|
// Matchers are used to "specialize" routes and focus on specific packet features.
|
||||||
type matcher interface {
|
// You can register attach them to a route via the AddMatcher method.
|
||||||
|
type Matcher interface {
|
||||||
Match(stanza.Packet, *RouteMatch) bool
|
Match(stanza.Packet, *RouteMatch) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue