Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
package readinglist
class Request(val method:String,val query:String,val contentType:String)
class Response(val contents:String,var status:Status){
fun status(status:Status.() -> Unit){
//do process
}
}
class Status(var code:Int,var description:String)
class RouteHandler(val request:Request,val response: Response){
var executeNext = false
fun next(){
executeNext=true
}
}
fun response(response:Response.() -> Unit){}
fun routeHandler(path:String,f:RouteHandler.() -> Unit):RouteHandler.() -> Unit = f
fun main(args: Array<String>) {
routeHandler("/index.html"){
if(request.query!=""){
//do process
}
response {
status {
code=404
description="Not Found"
}
}
}
}
package readinglist
//using invoke to invoke some functionality just by using instance
class Request(val method:String,val query:String,val contentType:String)
class Response(val contents:String,var status:Status){
operator fun invoke(status: Status.() -> Unit) {}
}
class Status(var code:Int,var description:String)
class RouteHandler(val request:Request,val response: Response){
var executeNext = false
fun next(){
executeNext=true
}
}
fun routeHandler(path:String,f:RouteHandler.() -> Unit):RouteHandler.() -> Unit = f
fun main(args: Array<String>) {
routeHandler("/index.html"){
if(request.query!=""){
//do process
}
response {
code=404
description="Not Found"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment