Skip to content

Commit

Permalink
improve(pack): add SessionOptions struct alias
Browse files Browse the repository at this point in the history
  • Loading branch information
cayter committed Jul 18, 2020
1 parent baaf790 commit 4db0c39
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 7 additions & 4 deletions pack/mdwsession.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ var (
mdwSessionCtxKey = ContextKey("sessionManager")
)

// SessionOptions defines the session cookie's configuration.
type SessionOptions = ginsessions.Options

// Sessioner stores the values and optional configuration for a session.
type Sessioner interface {
// AddFlash adds a flash message to the session.
Expand All @@ -41,7 +44,7 @@ type Sessioner interface {
Key() string

// Options sets the cookie configuration for a session.
Options(ginsessions.Options)
Options(SessionOptions)

// Set sets the session value associated to the given key.
Set(key interface{}, val interface{})
Expand Down Expand Up @@ -78,7 +81,7 @@ type SessionStore interface {
gorsessions.Store

// Options sets the cookie configuration for a session.
Options(ginsessions.Options)
Options(SessionOptions)

// KeyPrefix returns the prefix for the store key, not available for CookieStore.
KeyPrefix() string
Expand Down Expand Up @@ -113,7 +116,7 @@ func newSessionStore(config *support.Config) (SessionStore, error) {
}

if sessionStore != nil {
sessionStore.Options(ginsessions.Options{
sessionStore.Options(SessionOptions{
Domain: config.HTTPSessionCookieDomain,
HttpOnly: config.HTTPSessionCookieHTTPOnly,
MaxAge: config.HTTPSessionExpiration,
Expand Down Expand Up @@ -171,7 +174,7 @@ func (s *Session) Flashes(vars ...string) []interface{} {
}

// Options sets configuration for a session.
func (s *Session) Options(options ginsessions.Options) {
func (s *Session) Options(options SessionOptions) {
s.Session().Options = &gorsessions.Options{
Path: options.Path,
Domain: options.Domain,
Expand Down
9 changes: 4 additions & 5 deletions pack/mdwsession_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/appist/appy/support"
"github.com/appist/appy/test"
ginsessions "github.com/gin-contrib/sessions"
gorsessions "github.com/gorilla/sessions"
)

Expand Down Expand Up @@ -85,7 +84,7 @@ func (s *mdwSessionSuite) TestSessionCookieStore() {
mdwSession(s.config)(c)

session := c.Session()
session.Options(ginsessions.Options{
session.Options(SessionOptions{
MaxAge: 368400,
})
sessionCookie, _ := c.Cookie(s.config.HTTPSessionCookieName)
Expand Down Expand Up @@ -153,9 +152,9 @@ func (fss *fakeSessionStore) New(r *http.Request, name string) (*gorsessions.Ses
func (fss *fakeSessionStore) Get(r *http.Request, name string) (*gorsessions.Session, error) {
return nil, errors.New("not implemented")
}
func (fss *fakeSessionStore) KeyPrefix() string { return fss.keyPrefix }
func (fss *fakeSessionStore) SetKeyPrefix(p string) { fss.keyPrefix = p }
func (fss *fakeSessionStore) Options(ginsessions.Options) {}
func (fss *fakeSessionStore) KeyPrefix() string { return fss.keyPrefix }
func (fss *fakeSessionStore) SetKeyPrefix(p string) { fss.keyPrefix = p }
func (fss *fakeSessionStore) Options(SessionOptions) {}
func (fss *fakeSessionStore) Save(r *http.Request, w http.ResponseWriter, session *gorsessions.Session) error {
return nil
}
Expand Down

0 comments on commit 4db0c39

Please sign in to comment.