2018-12-04 19:15:41 +01:00
|
|
|
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},
|
2018-12-08 18:01:33 +01:00
|
|
|
route{"GetAll", "/getfromdb/{tableName}", getAll},
|
2018-12-04 19:15:41 +01:00
|
|
|
route{"GetOne", "/getfromdb/{primaryKey}", getIndex},
|
2018-12-18 22:09:23 +01:00
|
|
|
route{"UpdateRecord",
|
|
|
|
"/updaterec/{tableName}/pk/{primaryKey}/pkn/{primaryKeyName}/ftu/{fieldToUpdate}/vti/{valueToInsert}",
|
|
|
|
update},
|
|
|
|
route{"InsertRecord", "/insertrec/{tableName}/nr/{count}/pk/{primaryKey}/{val1}/{val2}/{val3}/{val4}/{val5}/{val6}/{val7}",
|
|
|
|
insert},
|
2018-12-04 19:15:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|