From 370893cdea2cfbcc42ce82c2d5c942db4d2359dc Mon Sep 17 00:00:00 2001 From: Hank Shen Date: Wed, 27 Oct 2021 11:30:19 +0800 Subject: update --- sessions.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sessions.go b/sessions.go index db4a57b..147889e 100644 --- a/sessions.go +++ b/sessions.go @@ -107,12 +107,17 @@ type sessionInfo struct { const registryKey = `webx:mw.sessions` // GetRegistry returns a registry instance for the current request. -func GetRegistry(ctx echo.Context) *Registry { - registry := &Registry{ +func GetRegistry(ctx echo.Context) (registry *Registry) { + actual, loaded := ctx.Internal().Load(registryKey) + if loaded { + registry = actual.(*Registry) + return + } + registry = &Registry{ context: ctx, sessions: make(map[string]sessionInfo), } - actual, loaded := ctx.Internal().LoadOrStore(registryKey, registry) + actual, loaded = ctx.Internal().LoadOrStore(registryKey, registry) if loaded { registry = actual.(*Registry) } -- cgit v1.2.3