This commit is contained in:
Tommi Reiman 2019-01-13 22:10:01 +02:00
parent 16499cceb1
commit 3168747540
2 changed files with 10 additions and 3 deletions

View file

@ -20,9 +20,15 @@
coll
coll))
(defn segments [path]
(defn segments
"Splits the path into sequence of segments, using `/` char. Assumes that the
path starts with `/`, stripping the first empty segment. e.g.
(segments \"/a/b/c\") ; => (\"a\" \"b\" \"c\")
(segments \"/a/) ; => (\"a\" \"\")"
[path]
#?(:clj (SegmentTrie/split ^String path)
:cljs (.split path #"/" 666)))
:cljs (rest (.split path #"/" 666))))
;;
;; https://github.com/pedestal/pedestal/blob/master/route/src/io/pedestal/http/route/prefix_tree.clj

View file

@ -57,6 +57,7 @@
:clj (.matcher ^SegmentTrie (or segment (SegmentTrie.)))))
(defn lookup [segment path]
#?(:cljs (-lookup segment (impl/segments path) {})
#?(:cljs (if-let [match (-lookup segment (impl/segments path) {})]
(assoc match :path-params (impl/url-decode-coll (:path-params match))))
:clj (if-let [match ^SegmentTrie$Match (SegmentTrie/lookup segment path)]
(->Match (.data match) (clojure.lang.PersistentHashMap/create (.params match))))))