Skip to content

Commit 43638fd

Browse files
committed
added the session to the current context and added a Session#GetOnce
method
1 parent f48afb0 commit 43638fd

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

default_context.go

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func (d *DefaultContext) Render(status int, rr render.Renderer) error {
106106
}
107107
data["params"] = pp
108108
data["flash"] = d.Flash().data
109+
data["session"] = d.Session()
109110
bb := &bytes.Buffer{}
110111

111112
err := rr.Render(bb, data)

session.go

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ func (s *Session) Get(name interface{}) interface{} {
2424
return s.Session.Values[name]
2525
}
2626

27+
// GetOnce gets a value from the current session and then deletes it.
28+
func (s *Session) GetOnce(name interface{}) interface{} {
29+
if x, ok := s.Session.Values[name]; ok {
30+
s.Delete(name)
31+
return x
32+
}
33+
return nil
34+
}
35+
2736
// Set a value onto the current session. If a value with that name
2837
// already exists it will be overridden with the new value.
2938
func (s *Session) Set(name, value interface{}) {

0 commit comments

Comments
 (0)