创建一个 Validator
Validator是Cloudopt Next的校验组件,主要用于RESTful注解上,与Intercept使用方法类似。
class TestValidator : Validator {override suspend fun validate(resource: Resource): Boolean {println("via ${this.javaClass.simpleName}")return true}override suspend fun error(resource: Resource) {resource.response.statusCode = 400resource.renderText("error")}}
使用 Validator
只需要在路由方法上声明 @Validator 即可。
@GET("/validator")@Validator([TestValidator::class, TestValidator2::class])fun testValidator() {renderText("success")}
