Skip to content

Commit

Permalink
httprouter to mux
Browse files Browse the repository at this point in the history
  • Loading branch information
mredencom committed Aug 25, 2021
1 parent dff7436 commit 5c4b9b4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ module github.com/php2go/netpollmux

go 1.15

require github.com/julienschmidt/httprouter v1.3.0
require (
github.com/gorilla/mux v1.8.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
6 changes: 3 additions & 3 deletions mux/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"sync"

"github.com/julienschmidt/httprouter"
"github.com/gorilla/mux"
"github.com/php2go/netpollmux/internal/logger"
"github.com/php2go/netpollmux/netpoll"
)
Expand All @@ -17,7 +17,7 @@ var DefaultServer = NewRoute()

// Route is an HTTP server.
type Route struct {
*httprouter.Router
*mux.Router
Handler http.Handler
// TLSConfig optionally provides a TLS configuration for use
// by ServeTLS and ListenAndServeTLS. Note that this value is
Expand All @@ -37,7 +37,7 @@ type Route struct {

// NewRoute returns a new NewRouter instance.
func NewRoute() *Route {
return &Route{Router: httprouter.New()}
return &Route{Router: mux.NewRouter()}
}

// SetFast enables the Server to use simple request parser.
Expand Down
5 changes: 2 additions & 3 deletions test/netpoll.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ import (
"net/http"
"sync"

"github.com/julienschmidt/httprouter"
"github.com/php2go/netpollmux/internal/logger"
"github.com/php2go/netpollmux/mux"
"github.com/php2go/netpollmux/netpoll"
)

func main() {
m := mux.NewRoute()
m.GET("/hello/:id", func(w http.ResponseWriter, req *http.Request, params httprouter.Params) {
m.HandleFunc("/hello/{id}", func(w http.ResponseWriter, req *http.Request) {
pp := req.URL.Query()
logger.Info("query params:", params, pp)
logger.Info("query params:", pp)
mux.JSON(w, req, []string{"hello world"}, http.StatusOK)
})
log.Fatal(m.Run(":8080"))
Expand Down

0 comments on commit 5c4b9b4

Please sign in to comment.