2015-11-03 26 views

回答

3

这是那么容易,因为

(def all-routes (concat api-routes site-routes)) 

解释从这里开始https://github.com/pedestal/pedestal/blob/master/guides/documentation/service-routing.md#defining-route-tables,更说明

路由表是一个简单的数据结构;在我们的例子中,它是一系列的地图。

底座团队调用序列图路由表形式为详细格式,他们设计的路由表的精简格式这就是我们提供给defroutedefroute然后将我们的简洁格式转换为详细格式。

您可以在REPL

;; here we supply a terse route format to defroutes 
> (defroutes routes 
    [[["/" {:get home-page} 
    ["/hello" {:get hello-world}]]]]) 
;;=> #'routes 

;; then we pretty print the verbose route format 
> (pprint routes) 
;;=> 
({:path-parts [""], 
    :path-params [], 
    :interceptors 
    [{:name :mavbozo-pedestal.core/home-page, 
    :enter 
    #object[io.pedestal.interceptor$eval7317$fn__7318$fn__7319 0x95d91f4 "[email protected]"], 
    :leave nil, 
    :error nil}], 
    :path "/", 
    :method :get, 
    :path-re #"/\Q\E", 
    :route-name :mavbozo-pedestal.core/home-page} 
{:path-parts ["" "hello"], 
    :path-params [], 
    :interceptors 
    [{:name :mavbozo-pedestal.core/hello-world, 
    :enter 
    #object[io.pedestal.interceptor$eval7317$fn__7318$fn__7319 0x4a168461 "[email protected]"], 
    :leave nil, 
    :error nil}], 
    :path "/hello", 
    :method :get, 
    :path-re #"/\Qhello\E", 
    :route-name :mavbozo-pedestal.core/hello-world}) 

因此,检查自己,因为底座路线只是地图的顺序,我们可以很容易地concat组合多个不重叠的路由。

这就是我喜欢的Clojure的原则,大约一个底座团队如下,其中:通用数据处理在这种情况下,一个详细的格式化的路由表只是一个地图 - 一个普通的Clojure的数据结构,它可以检查和使用常规clojure.core的数据结构操作函数(如concat)进行操作。即使是简洁的格式也是一种简单的clojure数据结构,可以用相同的方法轻松检查和操作。