gpt4 book ai didi

web - 如何创建 Restas 全局装饰器

转载 作者:太空宇宙 更新时间:2023-11-03 18:48:39 25 4
gpt4 key购买 nike

如何在 RESTAS 中创建全局装饰器?

;;;; defmodule.lisp
(in-package #:restas)
(defclass fake-server-route (routes:proxy-route) ())
(defun @fake-server (route)
(make-instance 'fake-server-route :target route))
(defmethod restas:process-route :before ((route fake-server-route) bindings)
(setf (hunchentoot:header-out :server) "Powered by NodeJS"))

(restas:define-module #:myapp
(:use #:cl #:st-json)
(:render-method #'st-json:write-json-to-string)
(:content-type "application/json")
(:decorators #'restas:@fake-server) ; this line here does not work
; it gives The symbol "@FAKE-SERVER" is not external in the RESTAS package.
)

(in-package #:myapp)

(defparameter *template-directory*
(merge-pathnames #P"templates/" myapp-config:*base-directory*))

(defparameter *static-directory*
(merge-pathnames #P"static/" myapp-config:*base-directory*))

如果我将@fake-server 设为其他包中的外部符号并尝试使用它,它仍然无法正常工作,它会给出如下内容:

defpackage error, unkown option :decorators

使用双冒号符号给出:

    COMPILE-FILE-ERROR while
compiling #<CL-SOURCE-FILE "myapp" "defmodule">
[Condition of type UIOP/LISP-BUILD:COMPILE-FILE-ERROR]

Backtrace:
0: (UIOP/LISP-BUILD:CHECK-LISP-COMPILE-RESULTS NIL T T "~/asdf-action::format-action/" ((#<ASDF/LISP-ACTION:COMPILE-OP > . #<ASDF/LISP-ACTION:CL-SOURCE-FILE "myapp" "defmodule">)))
1: ((SB-PCL::EMF ASDF/ACTION:PERFORM) #<unused argument> #<unused argument> #<ASDF/LISP-ACTION:COMPILE-OP > #<ASDF/LISP-ACTION:CL-SOURCE-FILE "myapp" "defmodule">)
2: ((:METHOD ASDF/ACTION:PERFORM-WITH-RESTARTS :AROUND (T T)) #<ASDF/LISP-ACTION:COMPILE-OP > #<ASDF/LISP-ACTION:CL-SOURCE-FILE "myapp" "defmodule">) [fast-method]
3: ((:METHOD ASDF/PLAN:PERFORM-PLAN (LIST)) ((#1=#<ASDF/LISP-ACTION:COMPILE-OP > . #<ASDF/SYSTEM:SYSTEM "alexandria">) (#1# . #<ASDF/COMPONENT:MODULE #2="trivial-features" "src">) (#1# . #<ASDF/SYSTEM:SY..
4: ((FLET SB-C::WITH-IT :IN SB-C::%WITH-COMPILATION-UNIT))
5: ((:METHOD ASDF/PLAN:PERFORM-PLAN :AROUND (T)) ((#1=#<ASDF/LISP-ACTION:COMPILE-OP > . #<ASDF/SYSTEM:SYSTEM "alexandria">) (#1# . #<ASDF/COMPONENT:MODULE #2="trivial-features" "src">) (#1# . #<ASDF/SYST..
6: ((FLET SB-C::WITH-IT :IN SB-C::%WITH-COMPILATION-UNIT))
7: ((:METHOD ASDF/PLAN:PERFORM-PLAN :AROUND (T)) #<ASDF/PLAN:SEQUENTIAL-PLAN {1009701223}> :VERBOSE NIL) [fast-method]
8: ((:METHOD ASDF/OPERATE:OPERATE (ASDF/OPERATION:OPERATION ASDF/COMPONENT:COMPONENT)) #<ASDF/LISP-ACTION:LOAD-OP :VERBOSE NIL> #<ASDF/SYSTEM:SYSTEM "myapp"> :VERBOSE NIL) [fast-method]
9: ((SB-PCL::EMF ASDF/OPERATE:OPERATE) #<unused argument> #<unused argument> #<ASDF/LISP-ACTION:LOAD-OP :VERBOSE NIL> #<ASDF/SYSTEM:SYSTEM "myapp"> :VERBOSE NIL)
10: ((LAMBDA NIL :IN ASDF/OPERATE:OPERATE))
11: ((:METHOD ASDF/OPERATE:OPERATE :AROUND (T T)) #<ASDF/LISP-ACTION:LOAD-OP :VERBOSE NIL> #<ASDF/SYSTEM:SYSTEM "myapp"> :VERBOSE NIL) [fast-method]
12: ((SB-PCL::EMF ASDF/OPERATE:OPERATE) #<unused argument> #<unused argument> ASDF/LISP-ACTION:LOAD-OP "myapp" :VERBOSE NIL)
13: ((LAMBDA NIL :IN ASDF/OPERATE:OPERATE))
14: (ASDF/CACHE:CALL-WITH-ASDF-CACHE #<CLOSURE (LAMBDA NIL :IN ASDF/OPERATE:OPERATE) {10096ADFDB}> :OVERRIDE NIL :KEY NIL)
15: ((:METHOD ASDF/OPERATE:OPERATE :AROUND (T T)) ASDF/LISP-ACTION:LOAD-OP "myapp" :VERBOSE NIL) [fast-method]
16: ((:METHOD ASDF/OPERATE:OPERATE :AROUND (T T)) ASDF/LISP-ACTION:LOAD-OP "myapp" :VERBOSE NIL) [fast-method]
17: ((LAMBDA NIL :IN QUICKLISP-CLIENT::APPLY-LOAD-STRATEGY))

最佳答案

The symbol "@FAKE-SERVER" is not external in the RESTAS package

您仍然可以使用双冒号表示法访问此符号,即 #'restas::@fake-server

但是,由于您不是 restas 包的作者,您可能希望在自己的包中定义 @fake-server 函数。

我无法帮助您解决后续问题,因为据我了解文档,您正确使用了 decoractors 选项。

关于web - 如何创建 Restas 全局装饰器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29787761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com