File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ package servemux
2+
3+ import (
4+ "net/http"
5+
6+ http2 "github.com/golang-plus/net/http"
7+
8+ "github.com/julienschmidt/httprouter"
9+ )
10+
11+ // New returns a new Router.
12+ func New () http2.ServeMux {
13+ return & ServeMux {
14+ Router : httprouter .New (),
15+ }
16+ }
17+
18+ type ServeMux struct {
19+ * httprouter.Router
20+ }
21+
22+ func (s * ServeMux ) ServeHTTP (rw http.ResponseWriter , req * http.Request ) {
23+ s .Router .ServeHTTP (rw , req )
24+ }
25+
26+ func (s * ServeMux ) wrap (handler http.Handler ) httprouter.Handle {
27+ return func (rw http.ResponseWriter , r * http.Request , params httprouter.Params ) {
28+ r2 := http2 .NewRequest (r )
29+ for _ , v := range params {
30+ r2 .SetParameter (v .Key , v .Value )
31+ }
32+ handler .ServeHTTP (rw , r2 .Request )
33+ }
34+ }
35+
36+ func (s * ServeMux ) Handle (method string , path string , handler http.Handler ) {
37+ s .Router .Handle (method , path , s .wrap (handler ))
38+ }
Original file line number Diff line number Diff line change 1+ {
2+ "comment" : " " ,
3+ "ignore" : " test" ,
4+ "package" : [
5+ {
6+ "checksumSHA1" : " ezRkrYYy9mMxREVDryjD5NlHa7M=" ,
7+ "path" : " github.com/julienschmidt/httprouter" ,
8+ "revision" : " 8c199fb6259ffc1af525cc3ad52ee60ba8359669" ,
9+ "revisionTime" : " 2015-04-21T17:00:07Z" ,
10+ "tree" : true ,
11+ "version" : " =v1.1" ,
12+ "versionExact" : " v1.1"
13+ }
14+ ],
15+ "rootPath" : " github.com/golang-plus/net-http-servemux"
16+ }
You can’t perform that action at this time.
0 commit comments