Compojure/Ring Routing错误:参数#错误

Ari*_*Ari 1 clojure compojure ring aleph

下面详细说明的路线设置会导致错误: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))
Run Code Online (Sandbox Code Playgroud)

mav*_*ozo 6

通过展开响应映射来修复您的登录功能

(defn sign-in [req]
  {:status 200 :body "hello world" :headers {"content-type" "text/plain"}}) 
Run Code Online (Sandbox Code Playgroud)

问题是,你把一个地图放在一个函数位置(列表的第一个元素),它需要一个参数.

(
  {:status 200 :body "hello world" :headers {"content-type" "text/plain"}} ;; function
  ???      ;; argument
 )
Run Code Online (Sandbox Code Playgroud)

在clojure中,map可以作为一个函数,以key作为参数,并返回该键的值,例如

({:a 1 :b 2 :c 3} :a)
=> 1
Run Code Online (Sandbox Code Playgroud)