router func
This commit is contained in:
parent
7b6e58685c
commit
8a70e29dce
25
router/router.go
Normal file
25
router/router.go
Normal file
@ -0,0 +1,25 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"github.com/gorilla/mux"
|
||||
"../logger"
|
||||
)
|
||||
|
||||
func NewRouter() *mux.Router {
|
||||
router := mux.NewRouter().StrictSlash(true)
|
||||
for _, route := range routes {
|
||||
var handler http.Handler
|
||||
|
||||
handler = route.HandlerFunc
|
||||
handler = logger.Logger(handler, route.Name)
|
||||
|
||||
router.
|
||||
Methods(route.Method).
|
||||
Path(route.Pattern).
|
||||
Name(route.Name).
|
||||
Handler(handler)
|
||||
}
|
||||
|
||||
return router
|
||||
}
|
22
router/routes.go
Normal file
22
router/routes.go
Normal file
@ -0,0 +1,22 @@
|
||||
package router
|
||||
|
||||
import "net/http"
|
||||
import "../test"
|
||||
|
||||
type Route struct {
|
||||
Name string
|
||||
Method string
|
||||
Pattern string
|
||||
HandlerFunc http.HandlerFunc
|
||||
}
|
||||
|
||||
type Routes []Route
|
||||
|
||||
var routes = Routes{
|
||||
Route{
|
||||
"Index",
|
||||
"GET",
|
||||
"/",
|
||||
test.Index,
|
||||
},
|
||||
}
|
Loading…
Reference in New Issue
Block a user