Skip to content

Commit

Permalink
Update examples for /v2 refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed May 10, 2024
1 parent 3214678 commit 5611ba6
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 42 deletions.
11 changes: 7 additions & 4 deletions examples/fastglue-goredis/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
6 changes: 3 additions & 3 deletions examples/fastglue-goredis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
20 changes: 11 additions & 9 deletions examples/fasthttp-redis/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
4 changes: 2 additions & 2 deletions examples/fasthttp-redis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 4 additions & 2 deletions examples/nethttp-inmemory/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
4 changes: 2 additions & 2 deletions examples/nethttp-inmemory/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
9 changes: 4 additions & 5 deletions examples/nethttp-redis/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
4 changes: 2 additions & 2 deletions examples/nethttp-redis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
9 changes: 6 additions & 3 deletions examples/nethttp-secure-cookie/go.mod
Original file line number Diff line number Diff line change
@@ -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
25 changes: 18 additions & 7 deletions examples/nethttp-secure-cookie/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions go.work
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
go 1.18
go 1.21

use (
.
./conv
./stores/goredis
./stores/memory
./stores/redis
./stores/securecookie
./stores/memory
)

0 comments on commit 5611ba6

Please sign in to comment.