Skip to content

Commit e00b1b4

Browse files
author
wayn3h0
committed
Merge branch 'dev'
first release v1.0.0
2 parents ef1302a + 7ce3bd2 commit e00b1b4

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

servemux.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
}

vendor/vendor.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}

0 commit comments

Comments
 (0)