@@ -14,22 +14,25 @@ type (
1414 PathRouter struct {
1515 mappings []mapping
1616 }
17- HttpHandlersPipe struct {
18- Handler Handler
19- Processors []Processor
20- }
2117 mapping struct {
2218 pattern string
2319 compiledPath urlpath.Path
2420 predicate RequestMatcher
25- handler * HttpHandlersPipe
21+ handler * HandlersPipe
2622 }
23+ // Result is a kind of adapter for response
24+ // to uniform v1 routing
25+ // GenericResult is generic result that can be used by processors
2726 Result struct {
28- Body string
29- Meta map [string ]string
30- StatusCode int
27+ Body string
28+ Meta map [string ]any
29+ StatusCode int
30+ GenericResult any
3131 }
3232
33+ // Request is kind of adapter for http.Request
34+ // to uniform v1 routing
35+ // it stores original http request
3336 Request struct {
3437 Method string
3538 Path string
4043
4144 Body string
4245 ParsedBody RequestBody
46+ // OriginalRequest is the original http.Request object that was received by the server.
47+ OriginalRequest * http.Request
4348 }
4449
4550 MatchResult struct {
@@ -56,14 +61,14 @@ type RequestMatcherFunc func(req *Request) MatchResult
5661func ServerErrorResult () * Result {
5762 return & Result {
5863 StatusCode : http .StatusInternalServerError ,
59- Meta : map [string ]string {"Content-Type" : "text/plain" },
64+ Meta : map [string ]any {"Content-Type" : "text/plain" },
6065 }
6166}
6267
6368func BadReqeustResult () * Result {
6469 return & Result {
6570 StatusCode : http .StatusBadRequest ,
66- Meta : map [string ]string {"Content-Type" : "text/plain" },
71+ Meta : map [string ]any {"Content-Type" : "text/plain" },
6772 }
6873}
6974
@@ -86,14 +91,14 @@ func (p *PathRouter) Clone() Cloner {
8691 return newRouter
8792}
8893
89- func (p * PathRouter ) Register (pattern string , predicate RequestMatcher , handler Handler ) {
94+ func (p * PathRouter ) Register (pattern string , predicate RequestMatcher , handler HTTPFrontendHandler ) {
9095
91- mapping := mapping {pattern , urlpath .New (pattern ), predicate , & HttpHandlersPipe {Handler : handler }}
96+ mapping := mapping {pattern , urlpath .New (pattern ), predicate , & HandlersPipe {Handler : handler }}
9297 p .mappings = append (p .mappings , mapping )
9398
9499}
95100
96- func (p * PathRouter ) Matches (req * Request ) (* HttpHandlersPipe , * Decision ) {
101+ func (p * PathRouter ) Matches (req * Request ) (* HandlersPipe , * Decision ) {
97102 handler , decision := p .findHandler (req )
98103 if handler != nil {
99104 routerStatistics .addMatched (req .Path )
@@ -104,7 +109,7 @@ func (p *PathRouter) Matches(req *Request) (*HttpHandlersPipe, *Decision) {
104109 }
105110}
106111
107- func (p * PathRouter ) findHandler (req * Request ) (* HttpHandlersPipe , * Decision ) {
112+ func (p * PathRouter ) findHandler (req * Request ) (* HandlersPipe , * Decision ) {
108113 path := strings .TrimSuffix (req .Path , "/" )
109114 for _ , m := range p .mappings {
110115 meta , match := m .compiledPath .Match (path )
@@ -192,11 +197,14 @@ func (p *PathRouter) GetFallbackHandler() HTTPFrontendHandler {
192197 panic ("not implemented" )
193198}
194199func (p * PathRouter ) GetHandlers () map [string ]HandlersPipe {
195- panic ("not implemented" )
200+ callInfos := make (map [string ]HandlersPipe )
201+ for _ , v := range p .mappings {
202+ callInfos [v .pattern ] = * v .handler
203+ }
204+ return callInfos
196205}
197206func (p * PathRouter ) SetHandlers (handlers map [string ]HandlersPipe ) {
198- panic ("not implemented" )
199- }
200- func (p * PathRouter ) Multiplexer () * http.ServeMux {
201- panic ("not implemented" )
207+ for path , handler := range handlers {
208+ p .mappings = append (p .mappings , mapping {pattern : path , compiledPath : urlpath .New (path ), handler : & handler })
209+ }
202210}
0 commit comments