mirror of
https://github.com/metosin/reitit.git
synced 2026-02-12 14:25:16 +00:00
Add :path & :method to Endpoints
This commit is contained in:
parent
06cb1301cd
commit
0dbb75ad44
1 changed files with 10 additions and 4 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
(def http-methods #{:get :head :patch :delete :options :post :put})
|
(def http-methods #{:get :head :patch :delete :options :post :put})
|
||||||
(defrecord Methods [get head post put delete trace options connect patch any])
|
(defrecord Methods [get head post put delete trace options connect patch any])
|
||||||
|
(defrecord Endpoint [data handler path method middleware])
|
||||||
|
|
||||||
(defn- group-keys [data]
|
(defn- group-keys [data]
|
||||||
(reduce-kv
|
(reduce-kv
|
||||||
|
|
@ -58,14 +59,19 @@
|
||||||
acc)) data http-methods)])
|
acc)) data http-methods)])
|
||||||
|
|
||||||
(defn compile-result [[path data] opts]
|
(defn compile-result [[path data] opts]
|
||||||
(let [[top childs] (group-keys data)]
|
(let [[top childs] (group-keys data)
|
||||||
|
->endpoint (fn [p d m s]
|
||||||
|
(-> (middleware/compile-result [p d] opts s)
|
||||||
|
(map->Endpoint)
|
||||||
|
(assoc :path p)
|
||||||
|
(assoc :method m)))]
|
||||||
(if-not (seq childs)
|
(if-not (seq childs)
|
||||||
(map->Methods {:any (middleware/compile-result [path top] opts)})
|
(map->Methods {:any (->endpoint path top :any nil)})
|
||||||
(reduce-kv
|
(reduce-kv
|
||||||
(fn [acc method data]
|
(fn [acc method data]
|
||||||
(let [data (meta-merge top data)]
|
(let [data (meta-merge top data)]
|
||||||
(assoc acc method (middleware/compile-result [path data] opts method))))
|
(assoc acc method (->endpoint path data method method))))
|
||||||
(map->Methods {:any (if (:handler top) (middleware/compile-result [path data] opts))})
|
(map->Methods {:any (if (:handler top) (->endpoint path data :any nil))})
|
||||||
childs))))
|
childs))))
|
||||||
|
|
||||||
(defn router
|
(defn router
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue