interface Middleware
The handler of a user attribute (attr Logged { … } + impl Middleware for Logged, then @Logged(…) on an rpc, §10.2): around
wraps every call of the rpc on the server, in the order the attributes are written (the first one is outermost). It runs code
before and after next(ctx), may refuse the call by returning Response.refuse(e) without calling next, and sees the context.
Example:
attr RequireUser {}
impl Middleware for RequireUser {
fn around(ctx: &var Ctx, next: Next) -> Response net, io, time, db {
match ctx.caller.userId() {
str _ => next(ctx)
AccessDenied _ => Response.refuse(AccessDenied{})
}
}
}
service Notes {
@public @RequireUser rpc add(text: str) -> i64
}
impl Notes {
rpc add(text) => 1
}@explicit pub(api) interface MiddlewareС версии. 1.0.0-beta
Методы
around | (ctx: &var Ctx, next: Next) -> Response net, io, time, dbWraps every call of the rpc the attribute is written on |
Определено в: std/core/rpc.oxl:525