下面详述的路由设置导致错误: Wrong number of args (0) passed to: PersistentArrayMap
谁能帮助我理解此错误以及如何解决它?
(defn sign-in [req]
({:status 200 :body "hello world" :headers {"content-type" "text/plain"}}))
(defroutes paths
(GET "/connect" {} connect-socket)
(POST "/sign-in" {} sign-in)
(route/resources "/")
(route/not-found "Resource not found."))
(def app
(-> (defaults/wrap-defaults #'paths defaults/api-defaults)
wrap-json-params))
通过解开响应映射来修复登录函数
(defn sign-in [req]
{:status 200 :body "hello world" :headers {"content-type" "text/plain"}})
问题是,你把一个地图放在一个函数位置(列表的第一个元素),它需要一个参数。
(
{:status 200 :body "hello world" :headers {"content-type" "text/plain"}} ;; function
??? ;; argument
)
在 Clojure 中,map 可以充当一个以 key 作为其参数的函数,并返回该键的值,例如
({:a 1 :b 2 :c 3} :a)
=> 1