Skip to content

Instantly share code, notes, and snippets.

@Tea-Ayataka
Created September 25, 2018 04:46
Show Gist options
  • Save Tea-Ayataka/2f4b971e6458f28b3d513305c7bfb5e4 to your computer and use it in GitHub Desktop.
Save Tea-Ayataka/2f4b971e6458f28b3d513305c7bfb5e4 to your computer and use it in GitHub Desktop.
fun PipelineContext<*, ApplicationCall>.setSession(id: String, value: String) {
val session = call.sessions.get<Session>() ?: Session()
session.data[id] = value
call.sessions.set(session)
}
fun PipelineContext<*, ApplicationCall>.getSession(id: String): String? {
return call.sessions.get<Session>()?.data?.get(id)
}
fun PipelineContext<*, ApplicationCall>.clearSession(id: String): String? {
return call.sessions.get<Session>()?.data?.remove(id)
}
class Session(val data: HashMap<String, String> = hashMapOf())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment