27 lines
450 B
Go
27 lines
450 B
Go
package router
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"nutfactory.org/Matrix/utils"
|
|
)
|
|
|
|
func NewRouter(routes Routes) *mux.Router {
|
|
router := mux.NewRouter().StrictSlash(true)
|
|
|
|
for _, route := range routes {
|
|
var handler http.Handler
|
|
handler = route.HandlerFunc
|
|
handler = utils.APILogger(handler, route.Name)
|
|
|
|
router.
|
|
Methods(route.Method).
|
|
Path(route.Pattern).
|
|
Name(route.Name).
|
|
Handler(handler)
|
|
|
|
}
|
|
|
|
return router
|
|
}
|