diff --git a/examples/fastglue-goredis/go.mod b/examples/fastglue-goredis/go.mod index 09ea855..7c4f562 100644 --- a/examples/fastglue-goredis/go.mod +++ b/examples/fastglue-goredis/go.mod @@ -3,8 +3,11 @@ module github.com/vividvilla/simplesessions/examples/fastglue-goredis go 1.16 require ( - github.com/go-redis/redis/v8 v8.11.1 - github.com/valyala/fasthttp v1.9.0 - github.com/vividvilla/simplesessions v0.2.0 - github.com/zerodha/fastglue v1.6.6 + github.com/fasthttp/router v1.5.0 // indirect + github.com/klauspost/compress v1.17.8 // indirect + github.com/redis/go-redis/v9 v9.5.1 + github.com/valyala/fasthttp v1.52.0 + github.com/vividvilla/simplesessions/stores/goredis/v9 v9.0.0 + github.com/vividvilla/simplesessions/v2 v2.0.0 + github.com/zerodha/fastglue v1.8.0 ) diff --git a/examples/fastglue-goredis/main.go b/examples/fastglue-goredis/main.go index 325ecff..6475d68 100644 --- a/examples/fastglue-goredis/main.go +++ b/examples/fastglue-goredis/main.go @@ -6,10 +6,10 @@ import ( "net/http" "time" - "github.com/go-redis/redis/v8" + "github.com/redis/go-redis/v9" "github.com/valyala/fasthttp" - "github.com/vividvilla/simplesessions" - redisstore "github.com/vividvilla/simplesessions/stores/goredis" + redisstore "github.com/vividvilla/simplesessions/stores/goredis/v9" + "github.com/vividvilla/simplesessions/v2" "github.com/zerodha/fastglue" ) diff --git a/examples/fasthttp-redis/go.mod b/examples/fasthttp-redis/go.mod index 09653e3..84fe957 100644 --- a/examples/fasthttp-redis/go.mod +++ b/examples/fasthttp-redis/go.mod @@ -1,14 +1,16 @@ module github.com/vividvilla/simplesessions/examples/fasthttp-redis +go 1.14 + require ( - github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6 // indirect - github.com/alicebob/miniredis v0.0.0-20180903194238-a6a1e4126522 // indirect github.com/gomodule/redigo v2.0.0+incompatible - github.com/klauspost/compress v1.4.0 // indirect - github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e // indirect - github.com/valyala/bytebufferpool v0.0.0-20160817181652-e746df99fe4a // indirect - github.com/valyala/fasthttp v0.0.0-20180901052036-d7688109a57b - github.com/vividvilla/simplesessions v0.0.1 - github.com/vividvilla/simplesessions/stores/redis v0.0.0-20180905073812-64bb2453ba8a - github.com/yuin/gopher-lua v0.0.0-20180827083657-b942cacc89fe // indirect + github.com/valyala/fasthttp v1.52.0 + github.com/vividvilla/simplesessions/stores/redis/v2 v2.0.0 + github.com/vividvilla/simplesessions/v2 v2.0.0 +) + +require ( + github.com/andybalholm/brotli v1.1.0 // indirect + github.com/klauspost/compress v1.17.6 // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect ) diff --git a/examples/fasthttp-redis/main.go b/examples/fasthttp-redis/main.go index 110025c..0ac0035 100644 --- a/examples/fasthttp-redis/main.go +++ b/examples/fasthttp-redis/main.go @@ -7,8 +7,8 @@ import ( "github.com/gomodule/redigo/redis" "github.com/valyala/fasthttp" - "github.com/vividvilla/simplesessions" - redisstore "github.com/vividvilla/simplesessions/stores/redis" + redisstore "github.com/vividvilla/simplesessions/stores/redis/v2" + "github.com/vividvilla/simplesessions/v2" ) var ( diff --git a/examples/nethttp-inmemory/go.mod b/examples/nethttp-inmemory/go.mod index a150d97..2ed9491 100644 --- a/examples/nethttp-inmemory/go.mod +++ b/examples/nethttp-inmemory/go.mod @@ -1,6 +1,8 @@ module github.com/vividvilla/simplesessions/examples/nethttp-inmemory +go 1.14 + require ( - github.com/vividvilla/simplesessions v0.0.1 - github.com/vividvilla/simplesessions/stores/memory v0.0.0-20180905073812-64bb2453ba8a + github.com/vividvilla/simplesessions/stores/memory/v2 v2.0.0 + github.com/vividvilla/simplesessions/v2 v2.0.0 ) diff --git a/examples/nethttp-inmemory/main.go b/examples/nethttp-inmemory/main.go index 8a53517..6382b34 100644 --- a/examples/nethttp-inmemory/main.go +++ b/examples/nethttp-inmemory/main.go @@ -5,8 +5,8 @@ import ( "log" "net/http" - "github.com/vividvilla/simplesessions" - "github.com/vividvilla/simplesessions/stores/memory" + "github.com/vividvilla/simplesessions/stores/memory/v2" + "github.com/vividvilla/simplesessions/v2" ) var ( diff --git a/examples/nethttp-redis/go.mod b/examples/nethttp-redis/go.mod index 58a4de2..ee59b93 100644 --- a/examples/nethttp-redis/go.mod +++ b/examples/nethttp-redis/go.mod @@ -1,10 +1,9 @@ module github.com/vividvilla/simplesessions/examples/nethttp-redis +go 1.14 + require ( - github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6 // indirect - github.com/alicebob/miniredis v0.0.0-20180903194238-a6a1e4126522 // indirect github.com/gomodule/redigo v2.0.0+incompatible - github.com/vividvilla/simplesessions v0.0.1 - github.com/vividvilla/simplesessions/stores/redis v0.0.0-20180905073812-64bb2453ba8a - github.com/yuin/gopher-lua v0.0.0-20180827083657-b942cacc89fe // indirect + github.com/vividvilla/simplesessions/stores/redis/v2 v2.0.0 + github.com/vividvilla/simplesessions/v2 v2.0.0 ) diff --git a/examples/nethttp-redis/main.go b/examples/nethttp-redis/main.go index 746d354..db7fc68 100644 --- a/examples/nethttp-redis/main.go +++ b/examples/nethttp-redis/main.go @@ -7,8 +7,8 @@ import ( "time" "github.com/gomodule/redigo/redis" - "github.com/vividvilla/simplesessions" - redisstore "github.com/vividvilla/simplesessions/stores/redis" + redisstore "github.com/vividvilla/simplesessions/stores/redis/v2" + "github.com/vividvilla/simplesessions/v2" ) var ( diff --git a/examples/nethttp-secure-cookie/go.mod b/examples/nethttp-secure-cookie/go.mod index d8ce223..f8debc2 100644 --- a/examples/nethttp-secure-cookie/go.mod +++ b/examples/nethttp-secure-cookie/go.mod @@ -1,7 +1,10 @@ module github.com/vividvilla/simplesessions/examples/nethttp-secure-cookie +go 1.14 + require ( - github.com/gorilla/securecookie v1.1.1 // indirect - github.com/vividvilla/simplesessions v0.0.1 - github.com/vividvilla/simplesessions/stores/securecookie v0.0.0-20180905073812-64bb2453ba8a + github.com/vividvilla/simplesessions/stores/securecookie/v2 v2.0.0 + github.com/vividvilla/simplesessions/v2 v2.0.0 ) + +require github.com/gorilla/securecookie v1.1.2 // indirect diff --git a/examples/nethttp-secure-cookie/main.go b/examples/nethttp-secure-cookie/main.go index 636f14b..29fd47d 100644 --- a/examples/nethttp-secure-cookie/main.go +++ b/examples/nethttp-secure-cookie/main.go @@ -5,13 +5,18 @@ import ( "log" "net/http" - "github.com/vividvilla/simplesessions" - "github.com/vividvilla/simplesessions/stores/securecookie" + "github.com/vividvilla/simplesessions/stores/securecookie/v2" + "github.com/vividvilla/simplesessions/v2" ) var ( sessionManager *simplesessions.Manager + store = securecookie.New( + []byte("0dIHy6S2uBuKaNnTUszB218L898ikGYA"), + []byte("0dIHy6S2uBuKaNnTUszB218L898ikGYA"), + ) + testKey = "abc123" testValue = 123456 ) @@ -29,7 +34,16 @@ func setHandler(w http.ResponseWriter, r *http.Request) { return } - if err = sess.Commit(); err != nil { + // For securecookies, ID() of the session is the encoded cookie + // data itself. + v, err := store.Flush(sess.ID()) + if err != nil { + http.Error(w, err.Error(), 500) + return + } + + // Write the cookie. + if err := sess.WriteCookie(v); err != nil { http.Error(w, err.Error(), 500) return } @@ -71,10 +85,7 @@ func setCookie(cookie *http.Cookie, w interface{}) error { func main() { sessionManager = simplesessions.New(simplesessions.Options{}) - sessionManager.UseStore(securecookie.New( - []byte("0dIHy6S2uBuKaNnTUszB218L898ikGYA"), - []byte("0dIHy6S2uBuKaNnTUszB218L898ikGYA"), - )) + sessionManager.UseStore(store) sessionManager.RegisterGetCookie(getCookie) sessionManager.RegisterSetCookie(setCookie) diff --git a/go.mod b/go.mod index 3aa6170..b8af66f 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,8 @@ module github.com/vividvilla/simplesessions/v2 -require github.com/stretchr/testify v1.9.0 +require ( + github.com/stretchr/testify v1.9.0 + github.com/valyala/fasthttp v1.40.0 +) go 1.14 diff --git a/go.work b/go.work index d814b3d..c30543b 100644 --- a/go.work +++ b/go.work @@ -1,10 +1,10 @@ -go 1.18 +go 1.21 use ( . ./conv ./stores/goredis + ./stores/memory ./stores/redis ./stores/securecookie - ./stores/memory )