我们试图使用API处理程序文档中的以下语法实现对API的no.of请求。
val app = Javalin.create {
it.defaultContentType = "application/json"
it.enableWebjars()
it.addStaticFiles("", Location.CLASSPATH)
it.enableCorsForAllOrigins()
it.dynamicGzip = true
}
app.options("/*") { ctx -> ctx.status(405) }
app.get("/*"){ctx ->
RateLimit(ctx).requestPerTimeUnit(5, TimeUnit.MINUTES) // throws if rate limit is exceeded
ctx.status("Hello, rate-limited World!") }但最终得到的是未解决的引用基准错误。这里有语法的指针吗?
我们用Kotlin来实现它。
发布于 2022-06-07 09:16:13
该库似乎更改了在不更新文档的情况下使用速率限制的方式。
改为使用以下代码:
NaiveRateLimit.requestPerTimeUnit(ctx, 5, TimeUnit.MINUTES)您还可以使用单个速率限制器实例,如下所示:
val rateLimiter = RateLimiter(TimeUnit.MINUTES)
app.get("/*"){ ctx ->
rateLimiter.incrementCounter(ctx, 5) // throws if rate limit is exceeded
ctx.status("Hello, rate-limited World!")
}https://stackoverflow.com/questions/70823924
复制相似问题