我试图找到一种方法来建立一个参数传递给这个函数(它是托盘的一部分):
(defn node-spec [& {:keys [image hardware location network qos] :as options}]
{:pre [(or (nil? image) (map? image))]}
options)
有效的是这种用法:
(node-spec :location {:location-id "eu-west-1a"}, :image {:image-id "eu-west-1/ami-937474e7"} :network {})
但是 :location 和 :image 位对于我要配置的所有机器都是通用的,而 :network {} 位对于每个节点都是不同的。所以我想把共同点排除在外,然后做这样的事情:
(def my-common-location-and-image {:location {:location-id "eu-west-1a"}, :image {:image-id "eu-west-1/ami-937474e7"}} )
(node-spec (merge {:network {:security-groups [ "group1" ] }} my-common-location-and-image ))
(node-spec (merge {:network {:security-groups [ "group1" ] }} my-common-location-and-image ))
但这不起作用。合并的映射被解析为缺少其值的单个键。所以我尝试了
(node-spec :keys (merge {:network {:security-groups [ "group1" ] }} my-common-location-and-image ))
和
(node-spec :options (merge {:network {:security-groups [ "group1" ] }} my-common-location-and-image ))
但这也不起作用。我觉得我正试图扭转或超越节点规范参数中的解构。我究竟做错了什么?或者我的目标是分解出一些键/值对是不可能的?