forked from Cookies_Github_mirror/AquaDX
[O] Make handlers abstract
This commit is contained in:
@@ -5,9 +5,7 @@ import ext.long
|
||||
import ext.parsing
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
|
||||
fun interface BaseHandler {
|
||||
@Throws(JsonProcessingException::class)
|
||||
fun handle(request: Map<String, Any>): Any?
|
||||
@@ -22,3 +20,11 @@ data class RequestContext(
|
||||
|
||||
typealias SpecialHandler = RequestContext.() -> Any?
|
||||
fun BaseHandler.toSpecial() = { ctx: RequestContext -> handle(ctx.data) }
|
||||
|
||||
// A very :3 way of declaring APIs
|
||||
abstract class MeowApi(val serialize: (String, Any?) -> String) {
|
||||
val initH = mutableMapOf<String, SpecialHandler>()
|
||||
infix operator fun String.invoke(fn: SpecialHandler) = initH.set("${this}Api", fn)
|
||||
infix fun List<String>.all(fn: SpecialHandler) = forEach { it(fn) }
|
||||
infix fun String.static(fn: () -> Any) = serialize(this, fn()).let { resp -> this { resp } }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user