diff controllers/routes.go @ 226:63dd5216eee4

Refactored gemma server to be more REST-like.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 26 Jul 2018 12:24:30 +0200
parents
children 694f959ba3e7
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/controllers/routes.go	Thu Jul 26 12:24:30 2018 +0200
@@ -0,0 +1,26 @@
+package controllers
+
+import (
+	"net/http"
+
+	"gemma.intevation.de/gemma/auth"
+
+	"github.com/gorilla/mux"
+)
+
+func BindRoutes(m *mux.Router) {
+
+	api := m.PathPrefix("/api").Subrouter()
+
+	sysAdmin := auth.EnsureRole("sys_admin")
+
+	api.Handle("/users", sysAdmin(createUser)).Methods(http.MethodPost)
+
+	api.HandleFunc("/login", token).
+		Methods(http.MethodGet, http.MethodPost)
+	api.Handle("/logout", auth.SessionMiddleware(http.HandlerFunc(token))).
+		Methods(http.MethodGet, http.MethodPost)
+	api.Handle("/renew", auth.SessionMiddleware(http.HandlerFunc(renew))).
+		Methods(http.MethodGet, http.MethodPost)
+
+}