diff pkg/controllers/routes.go @ 5711:2dd155cc95ec revive-cleanup

Fix all revive issue (w/o machine generated stuff).
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 20 Feb 2024 22:22:57 +0100
parents 2b862190aee4
children 6270951dda28
line wrap: on
line diff
--- a/pkg/controllers/routes.go	Tue Feb 20 21:28:56 2024 +0100
+++ b/pkg/controllers/routes.go	Tue Feb 20 22:22:57 2024 +0100
@@ -36,7 +36,7 @@
 	var (
 		sysAdmin      = auth.EnsureRole("sys_admin")
 		waterwayAdmin = auth.EnsureRole("waterway_admin")
-		any           = auth.EnsureRole("sys_admin", "waterway_admin", "waterway_user")
+		anyUser       = auth.EnsureRole("sys_admin", "waterway_admin", "waterway_user")
 	)
 
 	// Password resets.
@@ -50,7 +50,7 @@
 		Methods(http.MethodGet)
 
 	// User management.
-	api.Handle("/users", any(&mw.JSONHandler{
+	api.Handle("/users", anyUser(&mw.JSONHandler{
 		Handle: listUsers,
 	})).Methods(http.MethodGet)
 
@@ -59,16 +59,16 @@
 		Handle: createUser,
 	})).Methods(http.MethodPost)
 
-	api.Handle("/users/{user:.+}", any(&mw.JSONHandler{
+	api.Handle("/users/{user:.+}", anyUser(&mw.JSONHandler{
 		Handle: listUser,
 	})).Methods(http.MethodGet)
 
-	api.Handle("/users/{user:.+}", any(&mw.JSONHandler{
+	api.Handle("/users/{user:.+}", anyUser(&mw.JSONHandler{
 		Input:  func(*http.Request) interface{} { return new(models.User) },
 		Handle: updateUser,
 	})).Methods(http.MethodPut)
 
-	api.Handle("/users/{user:.+}", any(&mw.JSONHandler{
+	api.Handle("/users/{user:.+}", anyUser(&mw.JSONHandler{
 		Input:  func(*http.Request) interface{} { return new(models.UserPatch) },
 		Handle: patchUser,
 	})).Methods(http.MethodPatch)
@@ -89,12 +89,12 @@
 	})).Methods(http.MethodGet)
 
 	// System Settings
-	api.Handle("/system/config", any(&mw.JSONHandler{
+	api.Handle("/system/config", anyUser(&mw.JSONHandler{
 		Handle: getSystemConfig,
 		NoConn: true,
 	})).Methods(http.MethodGet)
 
-	api.Handle("/system/settings", any(&mw.JSONHandler{
+	api.Handle("/system/settings", anyUser(&mw.JSONHandler{
 		Handle: getSystemSettings,
 	})).Methods(http.MethodGet)
 
@@ -104,17 +104,17 @@
 	})).Methods(http.MethodPut)
 
 	// Print templates
-	api.Handle("/templates", any(&mw.JSONHandler{
+	api.Handle("/templates", anyUser(&mw.JSONHandler{
 		Handle: listPrintTemplates,
 	})).Methods(http.MethodGet)
 
 	tTypes := "{type:" + strings.Join(templateTypes, "|") + "}"
 
-	api.Handle("/templates/"+tTypes, any(&mw.JSONHandler{
+	api.Handle("/templates/"+tTypes, anyUser(&mw.JSONHandler{
 		Handle: listPrintTemplates,
 	})).Methods(http.MethodGet)
 
-	api.Handle("/templates/"+tTypes+"/{name}", any(&mw.JSONHandler{
+	api.Handle("/templates/"+tTypes+"/{name}", anyUser(&mw.JSONHandler{
 		Handle: fetchPrintTemplate,
 	})).Methods(http.MethodGet)
 
@@ -140,7 +140,7 @@
 		ModifyResponse: proxyModifyResponse("/api/external/"),
 	})
 
-	externalAuth := any(external)
+	externalAuth := anyUser(external)
 
 	api.Handle("/external/{hash}/{url}", externalAuth).
 		Methods(
@@ -158,7 +158,7 @@
 		ModifyResponse: proxyModifyResponse("/api/internal/"),
 	})
 
-	internalAuth := any(
+	internalAuth := anyUser(
 		mw.ModifyQuery(internal, mw.InjectUser))
 
 	api.Handle("/internal/{hash}/{url}", internalAuth).
@@ -171,35 +171,35 @@
 			http.MethodGet, http.MethodPost,
 			http.MethodPut, http.MethodDelete)
 
-	api.Handle("/published", any(&mw.JSONHandler{
+	api.Handle("/published", anyUser(&mw.JSONHandler{
 		Handle: published,
 		NoConn: true,
 	})).Methods(http.MethodGet)
 
 	// Survey selection
-	api.Handle("/surveys", any(&mw.JSONHandler{
+	api.Handle("/surveys", anyUser(&mw.JSONHandler{
 		Handle: listSurveys,
 	})).Methods(http.MethodGet).Queries("id", "{id}")
 
-	api.Handle("/surveys", any(&mw.JSONHandler{
+	api.Handle("/surveys", anyUser(&mw.JSONHandler{
 		Handle: listSurveys,
 	})).Methods(http.MethodGet).Queries("name", "{name}", "date", "{date}")
 
 	// difference calculation
-	api.Handle("/diff", any(&mw.JSONHandler{
+	api.Handle("/diff", anyUser(&mw.JSONHandler{
 		Input:  func(*http.Request) interface{} { return new(models.DiffCalculationInput) },
 		Handle: diffCalculation,
 		NoConn: true,
 	})).Methods(http.MethodPost)
 
 	// Cross sections
-	api.Handle("/cross", any(&mw.JSONHandler{
+	api.Handle("/cross", anyUser(&mw.JSONHandler{
 		Input:  func(*http.Request) interface{} { return new(models.CrossSectionInput) },
 		Handle: crossSection,
 	})).Methods(http.MethodPost)
 
 	// Feature search
-	api.Handle("/search", any(&mw.JSONHandler{
+	api.Handle("/search", anyUser(&mw.JSONHandler{
 		Input:  func(*http.Request) interface{} { return new(models.SearchRequest) },
 		Handle: searchFeature,
 	})).Methods(http.MethodPost)
@@ -340,7 +340,7 @@
 	// Handler for reporting
 
 	api.Handle("/data/reports",
-		any(&mw.JSONHandler{
+		anyUser(&mw.JSONHandler{
 			Handle: listReports,
 			NoConn: true,
 		})).Methods(http.MethodGet)
@@ -361,23 +361,23 @@
 
 	// Handler to serve data to the client.
 
-	api.Handle("/data/{type:availability|fairway}/{kind:stretch|section|bottleneck}/{name:.+}", any(
+	api.Handle("/data/{type:availability|fairway}/{kind:stretch|section|bottleneck}/{name:.+}", anyUser(
 		mw.DBConn(http.HandlerFunc(fairwayAvailability)))).Methods(http.MethodGet)
 
-	api.Handle("/data/stretch/shape/{name:.+}", any(
+	api.Handle("/data/stretch/shape/{name:.+}", anyUser(
 		mw.DBConn(http.HandlerFunc(stretchShapeDownload)))).Methods(http.MethodGet)
 
-	api.Handle("/data/waterlevels/{gauge:.+}", any(
+	api.Handle("/data/waterlevels/{gauge:.+}", anyUser(
 		mw.DBConn(http.HandlerFunc(waterlevels)))).Methods(http.MethodGet)
 
-	api.Handle("/data/longterm-waterlevels/{gauge:.+}", any(
+	api.Handle("/data/longterm-waterlevels/{gauge:.+}", anyUser(
 		mw.DBConn(http.HandlerFunc(longtermWaterlevels)))).Methods(http.MethodGet)
 
 	// TODO: gauge should not contain '/'s.
-	api.Handle("/data/year-waterlevels/{gauge}/{year:[0-9]+}", any(
+	api.Handle("/data/year-waterlevels/{gauge}/{year:[0-9]+}", anyUser(
 		mw.DBConn(http.HandlerFunc(yearWaterlevels)))).Methods(http.MethodGet)
 
-	api.Handle("/data/nash-sutcliffe/{gauge:.+}", any(&mw.JSONHandler{
+	api.Handle("/data/nash-sutcliffe/{gauge:.+}", anyUser(&mw.JSONHandler{
 		Handle: nashSutcliffe,
 	})).Methods(http.MethodGet)