张金坤 %!s(int64=8) %!d(string=hai) anos
pai
achega
7f46a1272a

+ 4 - 0
common/src/github.com/go-xweb/httpsession/IsRedisStore.go

@@ -0,0 +1,4 @@
+// IsRedisStore
+package httpsession
+
+var IsRedisSessionStore = false

+ 17 - 5
common/src/github.com/go-xweb/httpsession/manager.go

@@ -1,6 +1,7 @@
 package httpsession
 
 import (
+	"log"
 	"net/http"
 	"sync"
 	"time"
@@ -22,11 +23,22 @@ type Manager struct {
 }
 
 func Default() *Manager {
-	store := NewRedisStore(DefaultMaxAge)
-	key := string(GenRandKey(16))
-	return NewManager(store,
-		NewSha1Generator(key),
-		NewCookieTransfer("SESSIONID", DefaultMaxAge, false, "/"))
+	log.Println("IsRedisSessionStore", IsRedisSessionStore)
+	if IsRedisSessionStore {
+		store := NewRedisStore(DefaultMaxAge)
+		key := string(GenRandKey(16))
+		return NewManager(store,
+			NewSha1Generator(key),
+			NewCookieTransfer("SESSIONID", DefaultMaxAge, false, "/"))
+
+	} else {
+		store := NewMemoryStore(DefaultMaxAge)
+		key := string(GenRandKey(16))
+		return NewManager(store,
+			NewSha1Generator(key),
+			NewCookieTransfer("SESSIONID", DefaultMaxAge, false, "/"))
+
+	}
 }
 
 func NewManager(store Store, gen IdGenerator, transfer Transfer) *Manager {