Created
February 15, 2015 07:22
-
-
Save wavejumper/ed92bf6fb542f7e9dff6 to your computer and use it in GitHub Desktop.
observe-ring.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns foo.core | |
(:require [clojure.core.match :refer (match)] | |
[compojure.core :refer :all])) | |
(defn metrics [req resp] | |
(match [req resp] | |
[{:uri "/login"} {:status 401}] | |
(println "Failed login") | |
[{} {:status 500}] | |
(println "Application error") | |
:else (println "Nothing to report!"))) | |
(defn wrap-observe [handler observable-fn] | |
(fn [req] | |
(let [resp (handler req)] | |
(future (observable-fn req resp)) | |
resp))) | |
(def app | |
(routes (GET "/" [] "OK"))) | |
(wrap-observe app metrics) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment