Skip to content

Commit bf64792

Browse files
jamesgoodhousevishr
authored andcommitted
Fix panic from not checking for nil (#19)
* Fix panic from not checking for nil * add fmt package
1 parent fb243c4 commit bf64792

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

session/session.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package session
22

33
import (
4+
"fmt"
5+
46
"github.com/gorilla/context"
57
"github.com/gorilla/sessions"
68
"github.com/labstack/echo/v4"
@@ -32,7 +34,11 @@ var (
3234

3335
// Get returns a named session.
3436
func Get(name string, c echo.Context) (*sessions.Session, error) {
35-
store := c.Get(key).(sessions.Store)
37+
s := c.Get(key)
38+
if s == nil {
39+
return nil, fmt.Errorf("%q session not found", name)
40+
}
41+
store := s.(sessions.Store)
3642
return store.Get(c.Request(), name)
3743
}
3844

0 commit comments

Comments
 (0)