router func

This commit is contained in:
PawelJa 2018-11-24 20:48:46 +01:00
parent 7b6e58685c
commit 8a70e29dce
2 changed files with 47 additions and 0 deletions

25
router/router.go Normal file
View 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
View 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,
},
}