From ca33a035c779ae14fb6330c8801c75f49dd1bb79 Mon Sep 17 00:00:00 2001 From: Mitchell Riedstra Date: Sat, 7 Jan 2023 13:31:23 -0500 Subject: Add an internal caching option. It performs quite well. Also refactor and clean up most linter warnings. --- cmd/server/conditionalMiddleware.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 cmd/server/conditionalMiddleware.go (limited to 'cmd/server/conditionalMiddleware.go') diff --git a/cmd/server/conditionalMiddleware.go b/cmd/server/conditionalMiddleware.go new file mode 100644 index 0000000..60b1398 --- /dev/null +++ b/cmd/server/conditionalMiddleware.go @@ -0,0 +1,18 @@ +package main + +import "net/http" + +type conditionalMiddlewareFunc func(r *http.Request) bool + +// conditionalMiddleware simply uses handler a if condition is true and handler +// b if condition is false. +func conditionalMiddleware(condition conditionalMiddlewareFunc, + a, b http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if condition(r) { + a.ServeHTTP(w, r) + } else { + b.ServeHTTP(w, r) + } + }) +} -- cgit v1.2.3