diff options
author | Hank Shen <swhbox@foxmail.com> | 2021-10-27 06:30:19 +0300 |
---|---|---|
committer | Hank Shen <swhbox@foxmail.com> | 2021-10-27 06:30:19 +0300 |
commit | 370893cdea2cfbcc42ce82c2d5c942db4d2359dc (patch) | |
tree | dc3ebae24c6e1f60f8583a7d7a4fe2c94be0d602 /sessions.go | |
parent | 146fca184119daae9dd6f7d21ea9cf2b75ddbf7d (diff) |
updatev0.1.2
Diffstat (limited to 'sessions.go')
-rw-r--r-- | sessions.go | 11 |
1 files 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) } |