Add Models, Add Database

This commit is contained in:
hoernschen 2020-09-28 22:37:02 +02:00
parent 8f90344870
commit faee833481
21 changed files with 407 additions and 1 deletions

12
utils/router/route.go Normal file
View file

@ -0,0 +1,12 @@
package router
import "net/http"
type Route struct {
Name string
Method string
Pattern string
HandlerFunc http.HandlerFunc
}
type Routes []Route

27
utils/router/router.go Normal file
View file

@ -0,0 +1,27 @@
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
}