From 3f13707428ac0d2ea231f284ac30dd18b30b3137 Mon Sep 17 00:00:00 2001 From: Gerasimos Maropoulos Date: Tue, 26 Jul 2016 19:36:31 +0300 Subject: [PATCH] Expose a standard Session interface on context/context.go | https://github.com/kataras/iris/issues/316 --- context.go | 12 +----------- context/context.go | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/context.go b/context.go index dca4a5fa..82afc7cb 100644 --- a/context.go +++ b/context.go @@ -865,17 +865,7 @@ func (ctx *Context) SetFlash(key string, value string) { } // Session returns the current session -func (ctx *Context) Session() interface { - ID() string - Get(string) interface{} - GetString(key string) string - GetInt(key string) int - GetAll() map[string]interface{} - VisitAll(cb func(k string, v interface{})) - Set(string, interface{}) - Delete(string) - Clear() -} { +func (ctx *Context) Session() context.Session { if ctx.framework.sessions == nil { // this should never return nil but FOR ANY CASE, on future changes. return nil } diff --git a/context/context.go b/context/context.go index 1da485ca..17a49f24 100644 --- a/context/context.go +++ b/context/context.go @@ -9,6 +9,19 @@ import ( ) type ( + // Session is the domain-level session's store interface + // it's synced with the iris/sessions.go:session + Session interface { + ID() string + Get(string) interface{} + GetString(key string) string + GetInt(key string) int + GetAll() map[string]interface{} + VisitAll(cb func(k string, v interface{})) + Set(string, interface{}) + Delete(string) + Clear() + } // IContext the interface for the iris/context // Used mostly inside packages which shouldn't be import ,directly, the kataras/iris. @@ -71,17 +84,7 @@ type ( GetFlashes() map[string]string GetFlash(string) (string, error) SetFlash(string, string) - Session() interface { - ID() string - Get(string) interface{} - GetString(key string) string - GetInt(key string) int - GetAll() map[string]interface{} - VisitAll(cb func(k string, v interface{})) - Set(string, interface{}) - Delete(string) - Clear() - } + Session() Session SessionDestroy() Log(string, ...interface{}) Reset(*fasthttp.RequestCtx)