Debian Codegraph @

router_simple.go

raw symbols SCIP
1 // +build goji_router_simple
2
3 package goji
4
5 import "net/http"
6
7 /*
8 This is the simplest correct router implementation for Goji.
9 */
10
11 type router []route
12
13 type route struct {
14 Pattern
15 http.Handler
16 }
17
18 func (rt *router) add(p Pattern, h http.Handler) {
19 *rt = append(*rt, route{p, h})
20 }
21
22 func (rt *router) route(r *http.Request) *http.Request {
23 for _, route := range *rt {
24 if r2 := route.Match(r); r2 != nil {
25 return r2.WithContext(&match{
26 Context: r2.Context(),
27 p: route.Pattern,
28 h: route.Handler,
29 })
30 }
31 }
32 return r.WithContext(&match{Context: r.Context()})
33 }