mirror of
https://github.com/metosin/reitit.git
synced 2026-01-01 06:08:25 +00:00
clean
This commit is contained in:
parent
98a4d9b447
commit
f27c2fc2aa
5 changed files with 15 additions and 15 deletions
|
|
@ -60,11 +60,14 @@
|
|||
(defn map-data [f routes]
|
||||
(mapv (fn [[p ds]] [p (f p ds)]) routes))
|
||||
|
||||
(defn merge-data [{:keys [meta-merge]} p x]
|
||||
(defn meta-merge [left right opts]
|
||||
((or (:meta-merge opts) mm/meta-merge) left right))
|
||||
|
||||
(defn merge-data [opts p x]
|
||||
(reduce
|
||||
(fn [acc [k v]]
|
||||
(try
|
||||
((or meta-merge mm/meta-merge) acc {k v})
|
||||
(meta-merge acc {k v} opts)
|
||||
(catch #?(:clj Exception, :cljs js/Error) e
|
||||
(ex/fail! ::merge-data {:path p, :left acc, :right {k v}, :exception e}))))
|
||||
{} x))
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
(ns reitit.interceptor
|
||||
(:require [clojure.pprint :as pprint]
|
||||
[meta-merge.core :as mm]
|
||||
[reitit.core :as r]
|
||||
[reitit.exception :as exception]
|
||||
[reitit.impl :as impl]))
|
||||
|
|
@ -155,8 +154,8 @@
|
|||
:handler get-user}]])"
|
||||
([data]
|
||||
(router data nil))
|
||||
([data {:keys [meta-merge] :as opts}]
|
||||
(let [opts ((or meta-merge mm/meta-merge) {:compile compile-result} opts)]
|
||||
([data opts]
|
||||
(let [opts (impl/meta-merge {:compile compile-result} opts opts)]
|
||||
(r/router data opts))))
|
||||
|
||||
(defn interceptor-handler [router]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
(ns reitit.middleware
|
||||
(:require [clojure.pprint :as pprint]
|
||||
[meta-merge.core :as mm]
|
||||
[reitit.core :as r]
|
||||
[reitit.exception :as exception]
|
||||
[reitit.impl :as impl]))
|
||||
|
|
@ -138,8 +137,8 @@
|
|||
:handler get-user}]])"
|
||||
([data]
|
||||
(router data nil))
|
||||
([data {:keys [meta-merge] :as opts}]
|
||||
(let [opts ((or meta-merge mm/meta-merge) {:compile compile-result} opts)]
|
||||
([data opts]
|
||||
(let [opts (impl/meta-merge {:compile compile-result} opts opts)]
|
||||
(r/router data opts))))
|
||||
|
||||
(defn middleware-handler [router]
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
(ns reitit.http
|
||||
(:require [meta-merge.core :as mm]
|
||||
[reitit.core :as r]
|
||||
(:require [reitit.core :as r]
|
||||
[reitit.exception :as ex]
|
||||
[reitit.impl :as impl]
|
||||
[reitit.interceptor :as interceptor]
|
||||
[reitit.ring :as ring]))
|
||||
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
(update acc method expand opts)
|
||||
acc)) data ring/http-methods)])
|
||||
|
||||
(defn compile-result [[path data] {:keys [::default-options-endpoint expand meta-merge] :as opts}]
|
||||
(defn compile-result [[path data] {:keys [::default-options-endpoint expand] :as opts}]
|
||||
(let [[top childs] (ring/group-keys data)
|
||||
childs (cond-> childs
|
||||
(and (not (:options childs)) (not (:handler top)) default-options-endpoint)
|
||||
|
|
@ -38,7 +38,7 @@
|
|||
(->methods true top)
|
||||
(reduce-kv
|
||||
(fn [acc method data]
|
||||
(let [data ((or meta-merge mm/meta-merge) top data)]
|
||||
(let [data (impl/meta-merge top data opts)]
|
||||
(assoc acc method (->endpoint path data method method))))
|
||||
(->methods (:handler top) data)
|
||||
childs))))
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
(ns reitit.ring
|
||||
(:require [clojure.string :as str]
|
||||
[meta-merge.core :as mm]
|
||||
#?@(:clj [[ring.util.mime-type :as mime-type]
|
||||
[ring.util.response :as response]])
|
||||
[reitit.core :as r]
|
||||
|
|
@ -29,7 +28,7 @@
|
|||
(update acc method expand opts)
|
||||
acc)) data http-methods)])
|
||||
|
||||
(defn compile-result [[path data] {:keys [::default-options-endpoint expand meta-merge] :as opts}]
|
||||
(defn compile-result [[path data] {:keys [::default-options-endpoint expand] :as opts}]
|
||||
(let [[top childs] (group-keys data)
|
||||
childs (cond-> childs
|
||||
(and (not (:options childs)) (not (:handler top)) default-options-endpoint)
|
||||
|
|
@ -50,7 +49,7 @@
|
|||
(->methods true top)
|
||||
(reduce-kv
|
||||
(fn [acc method data]
|
||||
(let [data ((or meta-merge mm/meta-merge) top data)]
|
||||
(let [data (impl/meta-merge top data opts)]
|
||||
(assoc acc method (->endpoint path data method method))))
|
||||
(->methods (:handler top) data)
|
||||
childs))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue