@@ -11,6 +11,15 @@ import (
11
11
12
12
type Params = httprouter.Params
13
13
14
+ // Endpoint is a type that handlers can accepte as an input. It will be the
15
+ // combined URL path without path variables substituted. If you have
16
+ //
17
+ // mux.Get("/thing/:thingID", handler)
18
+ //
19
+ // and handler takes an nchi.Endpoint argument, and there is a request for
20
+ // http://example.com/thing/3802, then the nchi.Endpoint will be "/thing/:thingID".
21
+ type Endpoint string
22
+
14
23
type Mux struct {
15
24
providers * nject.Collection // partial set
16
25
routes []* Mux
@@ -86,30 +95,34 @@ func (mux *Mux) Bind() error {
86
95
for _ , opt := range mux .options {
87
96
opt (& rtr {router })
88
97
}
89
- err := mux .bind (router , "" , nject . Sequence ( "empty" ) )
98
+ err := mux .bind (router , "" )
90
99
if err != nil {
91
100
return err
92
101
}
93
102
mux .router = router
94
103
return nil
95
104
}
96
105
97
- func (mux * Mux ) bind (router * httprouter.Router , path string , providers * nject. Collection ) error {
106
+ func (mux * Mux ) bind (router * httprouter.Router , path string ) error {
98
107
combinedPath := path + mux .path
99
108
for _ , route := range mux .routes {
100
- err := route .bind (router , combinedPath , mux . providers )
109
+ err := route .bind (router , combinedPath )
101
110
if err != nil {
102
111
return err
103
112
}
104
113
}
114
+ providers := nject .Sequence (path ,
115
+ Endpoint (combinedPath ),
116
+ mux .providers ,
117
+ )
105
118
if mux .special != nil {
106
- return mux .bindSpecial (router , combinedPath , mux . providers )
119
+ return mux .bindSpecial (router , combinedPath , providers )
107
120
}
108
121
if mux .method == "" {
109
122
return nil
110
123
}
111
124
var handle httprouter.Handle
112
- err := mux . providers .Bind (& handle , nil )
125
+ err := providers .Bind (& handle , nil )
113
126
if err != nil {
114
127
return errors .Wrapf (err , "bind router %s %s" , mux .method , combinedPath )
115
128
}
0 commit comments