34 lines
557 B
Go
34 lines
557 B
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
type route struct {
|
|
Name string
|
|
Adres string
|
|
HandlerFunction http.HandlerFunc
|
|
}
|
|
|
|
type routes []route
|
|
|
|
var registredRoutes = routes{
|
|
route{"Index", "/", index},
|
|
route{"GetAll", "/getfromdb", getAll},
|
|
route{"GetOne", "/getfromdb/{primaryKey}", getIndex},
|
|
}
|
|
|
|
func newRouter() *mux.Router {
|
|
|
|
router := mux.NewRouter().StrictSlash(true)
|
|
for _, r := range registredRoutes {
|
|
router.
|
|
Path(r.Adres).
|
|
Name(r.Name).
|
|
Handler(r.HandlerFunction)
|
|
}
|
|
return router
|
|
}
|