33package quesma_api
44
55import (
6- "context"
76 "github.com/ucarion/urlpath"
87 "net/http"
98 "net/url"
@@ -15,12 +14,15 @@ type (
1514 PathRouter struct {
1615 mappings []mapping
1716 }
17+ HttpHandlersPipe struct {
18+ Handler Handler
19+ Processors []Processor
20+ }
1821 mapping struct {
1922 pattern string
2023 compiledPath urlpath.Path
2124 predicate RequestMatcher
22- handler Handler
23- processors []Processor
25+ handler * HttpHandlersPipe
2426 }
2527 Result struct {
2628 Body string
4042 ParsedBody RequestBody
4143 }
4244
43- Handler func (ctx context.Context , req * Request ) (* Result , error )
44-
4545 MatchResult struct {
4646 Matched bool
4747 Decision * Decision
@@ -78,14 +78,22 @@ func NewPathRouter() *PathRouter {
7878 return & PathRouter {mappings : make ([]mapping , 0 )}
7979}
8080
81+ func (p * PathRouter ) Clone () Cloner {
82+ newRouter := NewPathRouter ()
83+ for _ , mapping := range p .mappings {
84+ newRouter .Register (mapping .pattern , mapping .predicate , mapping .handler .Handler )
85+ }
86+ return newRouter
87+ }
88+
8189func (p * PathRouter ) Register (pattern string , predicate RequestMatcher , handler Handler ) {
8290
83- mapping := mapping {pattern , urlpath .New (pattern ), predicate , handler , nil }
91+ mapping := mapping {pattern , urlpath .New (pattern ), predicate , & HttpHandlersPipe { Handler : handler } }
8492 p .mappings = append (p .mappings , mapping )
8593
8694}
8795
88- func (p * PathRouter ) Matches (req * Request ) (Handler , * Decision ) {
96+ func (p * PathRouter ) Matches (req * Request ) (* HttpHandlersPipe , * Decision ) {
8997 handler , decision := p .findHandler (req )
9098 if handler != nil {
9199 routerStatistics .addMatched (req .Path )
@@ -96,7 +104,7 @@ func (p *PathRouter) Matches(req *Request) (Handler, *Decision) {
96104 }
97105}
98106
99- func (p * PathRouter ) findHandler (req * Request ) (Handler , * Decision ) {
107+ func (p * PathRouter ) findHandler (req * Request ) (* HttpHandlersPipe , * Decision ) {
100108 path := strings .TrimSuffix (req .Path , "/" )
101109 for _ , m := range p .mappings {
102110 meta , match := m .compiledPath .Match (path )
@@ -171,3 +179,24 @@ func (p *predicateAlways) Matches(req *Request) MatchResult {
171179func Always () RequestMatcher {
172180 return & predicateAlways {}
173181}
182+
183+ func (p * PathRouter ) AddRoute (path string , handler HTTPFrontendHandler ) {
184+ // TODO: it seems that we can adapt this to register call
185+ // p.Register(path, Always(), handler)
186+ panic ("not implemented" )
187+ }
188+ func (p * PathRouter ) AddFallbackHandler (handler HTTPFrontendHandler ) {
189+ panic ("not implemented" )
190+ }
191+ func (p * PathRouter ) GetFallbackHandler () HTTPFrontendHandler {
192+ panic ("not implemented" )
193+ }
194+ func (p * PathRouter ) GetHandlers () map [string ]HandlersPipe {
195+ panic ("not implemented" )
196+ }
197+ func (p * PathRouter ) SetHandlers (handlers map [string ]HandlersPipe ) {
198+ panic ("not implemented" )
199+ }
200+ func (p * PathRouter ) Multiplexer () * http.ServeMux {
201+ panic ("not implemented" )
202+ }
0 commit comments